From bf817f20eec423aef58a296b27e5ba0cb472b59e Mon Sep 17 00:00:00 2001 From: yflory Date: Wed, 25 Oct 2017 12:31:22 +0200 Subject: [PATCH] Fix file upload in code and slide --- www/common/common-file.js | 6 +++--- www/common/sframe-common-file.js | 2 ++ www/slide/inner.js | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/www/common/common-file.js b/www/common/common-file.js index 4501882b3..df2f94ee7 100644 --- a/www/common/common-file.js +++ b/www/common/common-file.js @@ -28,8 +28,8 @@ define([ var u8 = file.blob; // This is not a blob but a uint8array var metadata = file.metadata; - // if it exists, dropEvent contains the new pad location in the drive - var dropEvent = file.dropEvent; + // if it exists, path contains the new pad location in the drive + var path = file.path; var key = Nacl.randomBytes(32); var next = FileCrypto.encrypt(u8, metadata, key); @@ -76,7 +76,7 @@ define([ if (noStore) { return void onComplete(href); } - common.initialPath = dropEvent && dropEvent.path; + common.initialPath = path; common.renamePad(title || "", href, function (err) { if (err) { return void console.error(err); } onComplete(href); diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index aebec38e6..c8b1b7d7c 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -93,6 +93,8 @@ define([ var metadata = file.metadata; var id = file.id; var dropEvent = file.dropEvent; + delete file.dropEvent; + if (dropEvent.path) { file.path = dropEvent.path; } if (queue.inProgress) { return; } queue.inProgress = true; diff --git a/www/slide/inner.js b/www/slide/inner.js index bcfdc60f0..2dd47105f 100644 --- a/www/slide/inner.js +++ b/www/slide/inner.js @@ -376,6 +376,8 @@ define([ var andThen2 = function (editor, CodeMirror, framework, isPresentMode) { + var common = framework._.sfCommon; + var $contentContainer = $('#cp-app-slide-editor'); var $modal = $('#cp-app-slide-modal'); var $content = $('#cp-app-slide-modal-content'); @@ -427,6 +429,22 @@ define([ framework._.sfCommon.setTabTitle('{title}' + slideNumber); }); Slide.update(editor.getValue()); + + var fmConfig = { + dropArea: $('.CodeMirror'), + body: $('body'), + onUploaded: function (ev, data) { + //var cursor = editor.getCursor(); + //var cleanName = data.name.replace(/[\[\]]/g, ''); + //var text = '!['+cleanName+']('+data.url+')'; + var parsed = Cryptpad.parsePadUrl(data.url); + var hexFileName = Cryptpad.base64ToHex(parsed.hashData.channel); + var src = '/blob/' + hexFileName.slice(0,2) + '/' + hexFileName; + var mt = ''; + editor.replaceSelection(mt); + } + }; + common.createFileManager(fmConfig); }); framework.onDefaultContentNeeded(function () {