/** * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors * SPDX-License-Identifier: AGPL-3.0-or-later */ import './init-shared.js' import { emit } from '@nextcloud/event-bus' import { generateOcsUrl, getRootUrl, imagePath } from '@nextcloud/router' import { getRequestToken } from '@nextcloud/auth' import { loadState } from '@nextcloud/initial-state' import Config from './services/config.tsx' import { getUIDefaults, generateCSSVarTokens, getCollaboraTheme } from './helpers/coolParameters.js' import { enableScrollLock } from './helpers/mobileFixer.js' import PostMessageService from './services/postMessage.tsx' import { getCapabilities } from './services/capabilities.ts' import { callMobileMessage, isDirectEditing, isMobileInterfaceAvailable, } from './helpers/mobile.js' import { getWopiUrl, getSearchParam, getNextcloudUrl } from './helpers/url.js' import '../css/document.scss' import axios from '@nextcloud/axios' import { spawnDialog } from '@nextcloud/dialogs' import SaveAs from './components/Modal/SaveAs.vue' const PostMessages = new PostMessageService({ parent: window.parent, loolframe: () => document.getElementById('loleafletframe').contentWindow, }) if (isDirectEditing()) { enableScrollLock() } let checkingProxyStatus = false const checkProxyStatus = () => { checkingProxyStatus = true const url = Config.get('urlsrc').slice(0, Config.get('urlsrc').indexOf('proxy.php') + 'proxy.php'.length) $.get(url + '?status').done(function(val) { if (val && val.status && val.status !== 'OK') { if (val.status === 'starting' || val.status === 'stopped') { document.getElementById('proxyLoadingIcon').classList.add('icon-loading-small') document.getElementById('proxyLoadingMessage').textContent = t('richdocuments', 'Built-in CODE Server is starting up shortly, please wait.') } else if (val.status === 'restarting') { document.getElementById('proxyLoadingIcon').classList.add('icon-loading-small') document.getElementById('proxyLoadingMessage').textContent = t('richdocuments', 'Built-in CODE Server is restarting, please wait.') } else if (val.status === 'error') { if (val.error === 'appimage_missing') { document.getElementById('proxyLoadingMessage').textContent = t('richdocuments', 'Error: Cannot find the AppImage, please reinstall the Collabora Online Built-in server.') } else if (val.error === 'chmod_failed' || val.error === 'appimage_not_executable') { document.getElementById('proxyLoadingMessage').textContent = t('richdocuments', 'Error: Unable to make the AppImage executable, please setup a standalone server.') } else if (val.error === 'exec_disabled') { document.getElementById('proxyLoadingMessage').textContent = t('richdocuments', 'Error: Exec disabled in PHP, please enable it, or setup a standalone server.') } else if (val.error === 'not_linux' || val.error === 'not_x86_64' || val.error === 'not_aarch64') { document.getElementById('proxyLoadingMessage').textContent = t('richdocuments', 'Error: Not running on x86-64 or ARM64 (aarch64) Linux, please setup a standalone server.') } else if (val.error === 'no_fontconfig') { document.getElementById('proxyLoadingMessage').textContent = t('richdocuments', 'Error: The fontconfig library is not installed on your server, please install it or setup a standalone server.') } else if (val.error === 'no_glibc') { document.getElementById('proxyLoadingMessage').textContent = t('richdocuments', 'Error: Not running on glibc-based Linux, please setup a standalone server.') } else { document.getElementById('proxyLoadingMessage').textContent = t('richdocuments', 'Error: Cannot start the Collabora Online Built-in server, please setup a standalone one.') } // probably not even worth re-trying return } // retry... setTimeout(function() { checkProxyStatus() }, 100) return } checkingProxyStatus = false }) } const showLoadingIndicator = () => { if ((OC.appswebroots.richdocumentscode || OC.appswebroots.richdocumentscode_arm64) && Config.get('urlsrc').indexOf('proxy.php') >= 0) { checkProxyStatus() } else { document.getElementById('loadingContainer').classList.add('icon-loading') } } const hideLoadingIndicator = () => { if (checkingProxyStatus) { setTimeout(function() { hideLoadingIndicator() }, 100) return } document.getElementById('loadingContainer').classList.remove('icon-loading') document.getElementById('proxyLoadingIcon').classList.remove('icon-loading-small') document.getElementById('proxyLoadingMessage').textContent = '' } showLoadingIndicator() /** * Type definitions for WOPI Post message objects * * @typedef {object} View * @property {number} ViewId * @property {string} UserName * @property {string} UserId * @property {number} Color * @property {boolean} ReadOnly * @property {boolean} IsCurrentView */ const documentsMain = { isEditorMode: false, isViewerMode: false, isFrameReady: false, isPublic: false, ready: false, fileName: null, baseName: null, canShare: false, canEdit: false, renderComplete: false, // false till page is rendered with all required data about the document(s) $deferredVersionRestoreAck: null, wopiClientFeatures: null, users: [], // generates docKey for given fileId _generateDocKey(wopiFileId) { let canonicalWebroot = Config.get('canonical_webroot') let ocurl = getRootUrl() + '/index.php/apps/richdocuments/wopi/files/' + wopiFileId if (canonicalWebroot) { if (!canonicalWebroot.startsWith('/')) { canonicalWebroot = '/' + canonicalWebroot } Config.update('canonical_webroot', canonicalWebroot) ocurl = ocurl.replace(getRootUrl(), canonicalWebroot) } return ocurl }, UI: { /* Editor wrapper HTML */ container: '
' + '
', viewContainer: '
' + '
' + '
', showViewer(fileId, title) { // remove previous viewer, if open, and set a new one if (documentsMain.isViewerMode) { $('#revViewer').remove() $('#revViewerContainer').prepend($('
')) } const urlsrc = getWopiUrl({ fileId, title, readOnly: true, closeButton: !documentsMain.hideCloseButton }) // access_token & access_token_ttl - must be passed via a form post const accessToken = encodeURIComponent(documentsMain.token) const accessTokenTtl = encodeURIComponent(documentsMain.tokenTtl) // form to post the access token for WOPISrc const form = '
' + '' + '' + '' + '' + '' // buy product for new customer users + '' + '' + '
' // iframe that contains the Collabora Online Viewer const frame = '