From 7b026868fd4fbc0db710478e8f4005eee583e5a5 Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 22 Jan 2020 15:35:46 +0100 Subject: [PATCH] Fix images in onlyoffice --- www/common/onlyoffice/inner.js | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index 6580a421c..7f6d1df67 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -674,16 +674,22 @@ define([ case "saveChanges": // We're sending our changes to netflux handleChanges(obj, send); - try { - var docs = window.frames[0].AscCommon.g_oDocumentUrls.urls || {}; - var mediasSources = getMediasSources(); - Object.keys(mediasSources).forEach(function (name) { - if (!docs['media/'+name]) { - delete mediasSources[name]; - } - }); - APP.onLocal(); - } catch (e) {} + // If we're alone, clean up the medias + var m = metadataMgr.getChannelMembers().slice().filter(function (nId) { + return nId.length === 32; + }); + if (m.length === 1 && !APP.loadingImage) { + try { + var docs = window.frames[0].AscCommon.g_oDocumentUrls.urls || {}; + var mediasSources = getMediasSources(); + Object.keys(mediasSources).forEach(function (name) { + if (!docs['media/'+name]) { + delete mediasSources[name]; + } + }); + APP.onLocal(); + } catch (e) {} + } break; case "unLockDocument": if (obj.releaseLocks && content.locks && content.locks[getId()]) { @@ -829,6 +835,7 @@ define([ }); }; + APP.loadingImage = 0; APP.getImageURL = function(name, callback) { var mediasSources = getMediasSources(); var data = mediasSources[name]; @@ -844,10 +851,16 @@ define([ return void callback(blobUrl); } + APP.loadingImage++; Util.fetch(data.src, function (err, u8) { + if (err) { + APP.loadingImage--; + return void console.error(err); + } try { debug("Decrypt with key " + data.key); FileCrypto.decrypt(u8, Nacl.util.decodeBase64(data.key), function (err, res) { + APP.loadingImage--; if (err || !res.content) { debug("Decrypting failed"); return void callback(""); @@ -868,6 +881,7 @@ define([ callback(blobUrl); }); } catch (e) { + APP.loadingImage--; debug("Exception decrypting image " + data.name); console.error(e); callback("");