From d73b5e2b82ce856fa56b2ec885fde1f2d1883aea Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 24 Nov 2025 15:43:31 +0100 Subject: [PATCH] Integration API: Allow client download --- www/cryptpad-api.js | 5 +++++ www/integration/main.js | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/www/cryptpad-api.js b/www/cryptpad-api.js index 9a40d291b..03470c044 100644 --- a/www/cryptpad-api.js +++ b/www/cryptpad-api.js @@ -232,6 +232,11 @@ if (!config.events.onSave) { return void cb(); } config.events.onSave(data, cb); }); + chan.on('GET_BLOB', (data, cb) => { + getBlob((err, blob) => { + cb({error: err, blob}); + }); + }); chan.on('RELOAD', function () { config.document.blob = blob; if (!config.editorConfig) { // Not OnlyOffice shim diff --git a/www/integration/main.js b/www/integration/main.js index 4046d068c..b82bb52c3 100644 --- a/www/integration/main.js +++ b/www/integration/main.js @@ -161,6 +161,12 @@ define([ let getInstanceURL = function () { return Config.httpUnsafeOrigin; }; + let getBlobClient = (cb) => { + chan.send('GET_BLOB', obj => { + if (obj?.error) { console.error(obj?.error); } + cb(obj?.blob); + }); + }; let getBlobServer = function (documentURL, cb) { let xhr = new XMLHttpRequest(); let data = encodeURIComponent(documentURL); @@ -174,11 +180,11 @@ define([ // myBlob is now the blob that the object URL pointed to. cb(null, blob); } else { - cb(this.status); + getBlobClient(cb); } }; - xhr.onerror = function (e) { - cb(e.message); + xhr.onerror = function () { + getBlobClient(cb); }; xhr.send(); };