From 484aa93d9c166aa81d043f378b05fba890bfb065 Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 27 May 2026 15:16:49 +0200 Subject: [PATCH] fix(export): fix drive export issues with deleted files and office documents --- src/common/cryptget.js | 2 +- www/common/make-backup.js | 14 +++++----- www/common/onlyoffice/inner.js | 27 ++++++++++++++----- www/common/onlyoffice/ooiframe.js | 42 +++++++++++++++++------------ www/common/outer/x2t.js | 2 +- www/common/sframe-common-outer.js | 45 ++++++++++++++++++------------- www/common/worker.bundle.min.js | 2 +- 7 files changed, 83 insertions(+), 51 deletions(-) diff --git a/src/common/cryptget.js b/src/common/cryptget.js index d73a7e3ef..5b20ab5cc 100644 --- a/src/common/cryptget.js +++ b/src/common/cryptget.js @@ -83,7 +83,7 @@ const factory = (Crypto, CPNetflux, Netflux, Util, var config = { websocketURL: NetConfig.getWebsocketURL(opt.origin), channel: secret.channel, - validateKey: secret.keys.validateKey || undefined, + validateKey: secret.keys?.validateKey || undefined, crypto: Crypto.createEncryptor(secret.keys), logLevel: 0, initialState: opt.initialState, diff --git a/www/common/make-backup.js b/www/common/make-backup.js index fd386c0b5..8f0d93d5b 100644 --- a/www/common/make-backup.js +++ b/www/common/make-backup.js @@ -195,7 +195,7 @@ define([ var to; - var done = function () { + var done = Util.once(function () { if (ctx.stop) { return; } if (to) { clearTimeout(to); } //setTimeout(g, 2000); @@ -203,7 +203,7 @@ define([ ctx.updateProgress('download', {max: ctx.max, current: ctx.done}); g(); w(); - }; + }); var error = function (err) { if (ctx.stop) { return; } @@ -248,12 +248,13 @@ define([ }; transform(ctx, parsed.type, val, function (res) { if (ctx.stop) { return; } + if (res.error) { return void error(err); } if (!res.data) { return void error('EEMPTY'); } var fileName = getUnique(sanitize(rawName), res.ext, existingNames); existingNames.push(fileName.toLowerCase()); zip.file(fileName, res.data, opts); console.log('DONE ---- ' + fileName); - setTimeout(done, 500); + setTimeout(done, 1); }, { hash: parsed.hash, password: fData.password @@ -277,7 +278,7 @@ define([ existingNames.push(fileName.toLowerCase()); zip.file(fileName, res.content, opts); console.log('DONE ---- ' + fileName); - setTimeout(done, 1000); + setTimeout(done, 1); }); it = setInterval(function () { if (ctx.stop) { @@ -295,7 +296,7 @@ define([ var content = new Blob([fData.href, '\n'], { type: "text/plain;charset=utf-8" }); zip.file(fileName, content, opts); console.log('DONE ---- ' + fileName); - setTimeout(done, 1000); + setTimeout(done, 1); }; if (parsed.hashData.type === 'file') { return void todoFile(); @@ -344,7 +345,7 @@ define([ // Main function. Create the empty zip and fill it starting from drive.root var create = function (data, getPad, fileHost, cb, progress, cache, sframeChan) { if (!data || !data.uo || !data.uo.drive) { return void cb('EEMPTY'); } - var sem = Saferphore.create(5); + var sem = Saferphore.create(1); var ctx = { fileHost: fileHost, get: getPad, @@ -481,7 +482,6 @@ define([ var addErrors = function(errs) { if (!errs.length) { return; } var onClick = function() { - console.error('clicked?'); $(errors).toggle(); }; $(error).click(onClick).appendTo(actions); diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index 3711c587b..12b9e7738 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -851,13 +851,22 @@ define([ if (!exists) { return void UI.removeLoadingScreen(); } + let todo = ({blob, file, fileType}) => { + ooChannel.queue = messages.slice(1, minor+1); + resetData(blob, file || fileType); + UI.removeLoadingScreen(); + }; + if (!cp?.file) { + return loadDocument(true, true, void 0, todo); + } loadLastDocument(cp) - .then(({blob, fileType}) => { - ooChannel.queue = messages.slice(1, minor+1); - resetData(blob, fileType); - UI.removeLoadingScreen(); - }) - .catch(() => { + .then(todo) + .catch((err) => { + if (APP.isDownload) { + return void sframeChan.event('EV_OOIFRAME_DONE', { + error: 'INVALID' + }); + } if (cp.hash && vHashEl) { // We requested a checkpoint but we can't find it... UI.removeLoadingScreen(); @@ -3147,6 +3156,11 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null } content = json.content; readOnly = true; + if (!content.version || content.version <= 7) { + return void sframeChan.event('EV_OOIFRAME_DONE', { + error: 'MIGRATE' + }); + } var version = (!content.version || content.version === 1) ? 'v1/' : (content.version <= 3 ? 'v2b/' : OOCurrentVersion.currentVersion + '/'); var s = h('script', { @@ -3164,6 +3178,7 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null // minor version of 0. "openVersionHash" knows that it needs to give us the latest // version when "APP.isDownload" is true. var sheetVersion = lastIndex + '.0'; + ooLoaded = false; openVersionHash(sheetVersion); }); diff --git a/www/common/onlyoffice/ooiframe.js b/www/common/onlyoffice/ooiframe.js index 2530daf58..e07b8e9d5 100644 --- a/www/common/onlyoffice/ooiframe.js +++ b/www/common/onlyoffice/ooiframe.js @@ -12,27 +12,34 @@ define([ ], function (nThen, ApiConfig, $, RequireConfig, Messages) { var requireConfig = RequireConfig(); - var ready = false; - var currentCb; - var queue = []; + //var ready = false; + const state = {}; + ['doc', 'sheet', 'presentation'].forEach(app => { + state[app] = { + ready: false, + queue: [], + cb: undefined + }; + }); var create = function (config) { + const s = state[config.type]; // Loaded in load #2 var sframeChan; var Util = config.modules.Utils.Util; var _onReadyEvt = Util.mkEvent(true); var refresh = function (data, cb) { - if (currentCb) { - queue.push({data: data, cb: cb}); + if (s.cb) { + s.queue.push({data: data, cb: cb}); return; } - if (!ready) { + if (!s.ready) { _onReadyEvt.reg(function () { refresh(data, cb); }); return; } - currentCb = cb; + s.cb = cb; sframeChan.event('EV_OOIFRAME_REFRESH', data); }; nThen(function (waitFor) { @@ -50,8 +57,8 @@ define([ }; window.rc = requireConfig; window.apiconf = ApiConfig; - $('#sbox-oo-iframe').attr('src', - ApiConfig.httpSafeOrigin + '/sheet/inner.html?' + requireConfig.urlArgs + + $(`#sbox-oo-iframe-${config.type}`).attr('src', + ApiConfig.httpSafeOrigin + `/${config.type}/inner.html?` + requireConfig.urlArgs + '#' + encodeURIComponent(JSON.stringify(req))); // This is a cheap trick to avoid loading sframe-channel in parallel with the @@ -76,7 +83,7 @@ define([ // First, we have to answer to this message, otherwise we're going to block // sframe-boot.js. Then we can start the channel. var msgEv = Utils.Util.mkEvent(); - var iframe = $('#sbox-oo-iframe')[0].contentWindow; + var iframe = $(`#sbox-oo-iframe-${config.type}`)[0].contentWindow; var postMsg = function (data) { iframe.postMessage(data, '*'); }; @@ -122,6 +129,7 @@ define([ pathname: window.location.pathname, feedbackAllowed: Utils.Feedback.state, secureIframe: true, + ooType: config.type, supportsWasm: Utils.Util.supportsWasm() }; for (var k in additionalPriv) { metaObj.priv[k] = additionalPriv[k]; } @@ -139,15 +147,15 @@ define([ }); sframeChan.on('EV_OOIFRAME_DONE', function (data) { - if (queue.length) { + if (s.queue.length) { setTimeout(function () { - var first = queue.shift(); + var first = s.queue.shift(); refresh(first.data, first.cb); }); } - if (!currentCb) { return; } - currentCb(data); - currentCb = undefined; + if (!s.cb) { return; } + s.cb(data); + s.cb = undefined; }); // X2T @@ -157,8 +165,8 @@ define([ }); sframeChan.onReady(function () { - if (ready === true) { return; } - ready = true; + if (s.ready) { return; } + s.ready = true; _onReadyEvt.fire(); }); }); diff --git a/www/common/outer/x2t.js b/www/common/outer/x2t.js index 4875e9748..822ae4beb 100644 --- a/www/common/outer/x2t.js +++ b/www/common/outer/x2t.js @@ -230,7 +230,7 @@ define([ }; var convert = function (obj, cb) { - console.error(obj); + //console.error(obj); obj.fileName = sanitize(obj.fileName); getX2T(function (x2t) { // Fonts diff --git a/www/common/sframe-common-outer.js b/www/common/sframe-common-outer.js index e95389659..a2714e459 100644 --- a/www/common/sframe-common-outer.js +++ b/www/common/sframe-common-outer.js @@ -1910,7 +1910,7 @@ define([ UnsafeObject.$iframe = $('