From e730be0a36f23db82b72cfd9d4aa63a13a0df1fd Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 11 Feb 2025 15:47:04 +0100 Subject: [PATCH] More customization --- www/common/onlyoffice/inner.js | 45 ++++++++++++++++++++++++++++------ www/cryptpad-api.js | 22 +++++++++++++++-- www/integration/main.js | 3 ++- 3 files changed, 59 insertions(+), 11 deletions(-) diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index 64a7af21b..313ebf468 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -1685,16 +1685,20 @@ define([ || metadataMgr.getUserData().name || Messages.anonymous; + let integrationConfig = privateData?.integrationConfig?._; + let ec = integrationConfig?.editorConfig; + let dc = integrationConfig?.document; + // Config APP.ooconfig = { - "document": { - "fileType": file.type, - "key": "fresh", - "title": file.title, - "url": url, - "permissions": { - "download": false, - "print": true, + document: { + fileType: file.type, + key: "fresh", + title: dc?.title || file.title, + url: url, + permissions: { + download: dc?.permissions?.download || false, + print: dc?.permissions?.print || true, } }, "documentType": file.doc, @@ -2140,6 +2144,31 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null }, void 0, common.getCache()); }; + let copy = (a, b) => { + Object.keys(b).forEach(k => { + if (a[k]) { + if (typeof(a[k]) === "object" && typeof(b[k]) === "object") { + copy(a[k], b[k]); + } + return; + } + a[k] = b[k]; + }); + }; + let integrationConfig = privateData?.integrationConfig?._; + if (integrationConfig) { + let ec = integrationConfig.editorConfig; + copy(APP.ooconfig.editorConfig, ec); + // Open "goback" in new tabs because of csp and + // iframes + if (ec.editorConfig?.customization?.goback) { + let c = APP.ooconfig.editorConfig.customization; + c.goback.blank = true; + } + } + console.error('updated config', APP.ooconfig); + + APP.docEditor = new window.DocsAPI.DocEditor("cp-app-oo-placeholder-a", APP.ooconfig); ooLoaded = true; makeChannel(); diff --git a/www/cryptpad-api.js b/www/cryptpad-api.js index bef2bbe91..cf115c32e 100644 --- a/www/cryptpad-api.js +++ b/www/cryptpad-api.js @@ -112,6 +112,18 @@ xhr.send(); }; + let serializedConfig = () => { + let _config = {}; + _config.editorConfig = config.editorConfig; + _config.document = { + permissions: config.document?.permissions, + title: config.document?.title, + info: config.document?.info, + referenceData: config.document?.referenceData + }; + return _config; + }; + var start = function () { //config.document.key = key; chan.send('START', { @@ -123,7 +135,8 @@ document: blob, ext: config.document.fileType, autosave: config.events.onSave && (config.autosave || 10), - editorConfig: config.editorConfig || {} + editorConfig: config.editorConfig || {}, + _config: serializeConfig() }, function (obj) { if (obj && obj.error) { reject(obj.error); return console.error(obj.error); } resolve({}); @@ -137,7 +150,12 @@ blob = config.document.blob; return start(); } - // XXX Nextcloud will log us out if we try from the client + // NOTE: Nextcloud will log us out if we try from the client + // TODO: make sure the server plugin is installed if we don't + // call getBlob() + if (!config.events?.onSave) { + return void start(); + } getBlob(function (err, _blob) { if (err) { // Can't get blob from client, try from server console.warn(err); diff --git a/www/integration/main.js b/www/integration/main.js index 4cc88974e..c23a0840e 100644 --- a/www/integration/main.js +++ b/www/integration/main.js @@ -243,7 +243,8 @@ define([ fileName: data.name, fileType: data.ext, autosave: data.autosave, - user: data.editorConfig.user + user: data.editorConfig.user, + _: data._config }, utils: { onReady: onReady,