diff --git a/www/common/onlyoffice/inner.js b/www/common/onlyoffice/inner.js index 9faa7afc2..5184833c7 100644 --- a/www/common/onlyoffice/inner.js +++ b/www/common/onlyoffice/inner.js @@ -392,6 +392,10 @@ define([ }; var onUploaded = function (ev, data, err) { + if (!ev && err) { + console.error(err); + return void UI.warn(Messages.error); + } if (ev.newTemplate) { if (err) { console.error(err); @@ -549,7 +553,7 @@ define([ var saveToServer = function (blob, title) { if (APP.cantCheckpoint) { return; } // TOO_LARGE - var text = getContent(); + var text = !blob && getContent(); if (!text && !blob) { setEditable(false, true); sframeChan.query('Q_CLEAR_CACHE_CHANNELS', [ @@ -3154,9 +3158,9 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null return void UI.errorLoadingScreen(Messages.error); } var blob = new Blob([bin], {type: 'text/plain'}); - var file = getFileType(); - resetData(blob, file); - //saveToServer(blob, title); + //var file = getFileType(); + //resetData(blob, file); + saveToServer(blob, title); Title.updateTitle(title); UI.removeLoadingScreen(); }); @@ -3205,7 +3209,7 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null cb(); }); }); - if (privateData.initialState) { + if (privateData.initialState && (!content || !content.hashes)) { var blob = privateData.initialState; let title = `document.${cfg.fileType}`; console.error(blob, title); diff --git a/www/common/outer/async-store.js b/www/common/outer/async-store.js index cd93675fe..9ba3853e0 100644 --- a/www/common/outer/async-store.js +++ b/www/common/outer/async-store.js @@ -467,6 +467,19 @@ define([ }); }; + var initTempRpc = (clientId, cb) => { + if (store.rpc) { return void cb(store.rpc); } + var kp = Crypto.Nacl.sign.keyPair(); + var keys = { + edPublic: Crypto.Nacl.util.encodeBase64(kp.publicKey), + edPrivate: Crypto.Nacl.util.encodeBase64(kp.secretKey) + }; + Pinpad.create(store.network, keys, function (e, call) { + if (e) { return void cb({error: e}); } + store.rpc = call; + cb(call); + }); + }; var initRpc = function (clientId, data, cb) { if (!store.loggedIn) { return cb(); } if (store.rpc) { return void cb(account); } @@ -3149,7 +3162,7 @@ define([ // If we load CryptPad for the first time from an existing pad, don't create a // drive automatically. - var onNoDrive = function (clientId, cb) { + var onNoDrive = function (clientId, cb, initRpc) { var andThen = function () { // To be able to use all the features inside the pad, we need to // initialize the chat (messenger) and the cursor modules. @@ -3160,9 +3173,16 @@ define([ store.messenger = store.modules['messenger']; // And now we're ready - initAnonRpc(null, null, function () { - cb({}); - }); + let getAnon = () => { + initAnonRpc(null, null, function () { + cb({}); + }); + }; + + if (initRpc) { + return initTempRpc(clientId, getAnon); + } + getAnon(); }; // We need an anonymous RPC to be able to check if the pad exists and to get @@ -3245,7 +3265,7 @@ define([ // First tab, no user hash, no anon hash and this app doesn't need a drive // ==> don't create a drive // Or "neverDrive" (integration into another platform?) - // ==> don't create a drive + // ==> don't create a drive BUT create temp RPC (we may need to upload) if (data.neverDrive || (data.noDrive && !data.userHash && !data.anonHash)) { return void onNoDrive(clientId, function (obj) { if (obj && obj.error) { @@ -3259,7 +3279,7 @@ define([ } Feedback.send("NO_DRIVE", true); callback(obj); - }); + }, !!data.neverDrive); } initialized = true; diff --git a/www/cryptpad-api.js b/www/cryptpad-api.js index e73ef40bd..cdbf7f8dd 100644 --- a/www/cryptpad-api.js +++ b/www/cryptpad-api.js @@ -188,6 +188,7 @@ chan.on('ON_DOWNLOADAS', blob => { let url = URL.createObjectURL(blob); + if (!config.events.onDownloadAs) { return; } config.events.onDownloadAs({ data: { fileType: config.document && config.document.fileType, @@ -198,6 +199,7 @@ chan.on('SAVE', function (data, cb) { blob = data; + if (!config.events.onSave) { return void cb(); } config.events.onSave(data, cb); }); chan.on('RELOAD', function () {