From aa744567ed8aaa853e30886ce5af2dbe3f4eaeb0 Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 9 Oct 2017 11:52:34 +0200 Subject: [PATCH] Fix thumbnails in sframe apps --- www/common/common-file.js | 1 + www/common/cryptpad-common.js | 4 +-- www/common/sframe-common-file.js | 43 ++++++++++++++++++++++---------- www/file/inner.js | 2 +- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/www/common/common-file.js b/www/common/common-file.js index 0c3eadd36..6b1f33505 100644 --- a/www/common/common-file.js +++ b/www/common/common-file.js @@ -76,6 +76,7 @@ define([ common.renamePad(title || "", href, function (err) { if (err) { return void console.error(err); } onComplete(href); + common.setPadAttribute('fileType', metadata.type, null, href); }); }); }; diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 863d97d07..a6f830354 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -489,8 +489,8 @@ define([ }; // STORAGE - common.setPadAttribute = function (attr, value, cb) { - var href = getRelativeHref(window.location.href); + common.setPadAttribute = function (attr, value, cb, href) { + href = getRelativeHref(href || window.location.href); getStore().setPadAttribute(href, attr, value, cb); }; common.setDisplayName = function (value, cb) { diff --git a/www/common/sframe-common-file.js b/www/common/sframe-common-file.js index 10bb8fbac..a2abd006a 100644 --- a/www/common/sframe-common-file.js +++ b/www/common/sframe-common-file.js @@ -1,8 +1,9 @@ define([ 'jquery', '/file/file-crypto.js', + '/common/common-thumbnail.js', '/bower_components/tweetnacl/nacl-fast.min.js', -], function ($, FileCrypto) { +], function ($, FileCrypto, Thumb) { var Nacl = window.nacl; var module = {}; @@ -220,30 +221,46 @@ define([ var handleFile = File.handleFile = function (file, e, thumbnail) { var thumb; - var finish = function (arrayBuffer) { + var file_arraybuffer; + var finish = function () { var metadata = { name: file.name, type: file.type, }; if (thumb) { metadata.thumbnail = thumb; } queue.push({ - blob: arrayBuffer, + blob: file_arraybuffer, metadata: metadata, dropEvent: e }); }; - var processFile = function () { - blobToArrayBuffer(file, function (e, buffer) { - finish(buffer); - }); - }; - - if (!thumbnail) { return void processFile(); } - blobToArrayBuffer(thumbnail, function (e, buffer) { + blobToArrayBuffer(file, function (e, buffer) { if (e) { console.error(e); } - thumb = arrayBufferToString(buffer); - processFile(); + file_arraybuffer = buffer; + if (thumbnail) { // there is already a thumbnail + return blobToArrayBuffer(thumbnail, function (e, buffer) { + if (e) { console.error(e); } + thumb = arrayBufferToString(buffer); + finish(); + }); + } + + if (!Thumb.isSupportedType(file.type)) { return finish(); } + // make a resized thumbnail from the image.. + Thumb.fromImageBlob(file, function (e, thumb_blob) { + if (e) { console.error(e); } + if (!thumb_blob) { return finish(); } + + blobToArrayBuffer(thumb_blob, function (e, buffer) { + if (e) { + console.error(e); + return finish(); + } + thumb = arrayBufferToString(buffer); + finish(); + }); + }); }); }; diff --git a/www/file/inner.js b/www/file/inner.js index 55e7487a1..df5ba854f 100644 --- a/www/file/inner.js +++ b/www/file/inner.js @@ -77,7 +77,7 @@ define([ sfCommon: common, }; if (uploadMode) { - displayed.push('pageTitle'); //TODO in toolbar + displayed.push('pageTitle'); configTb.pageTitle = Messages.upload_title; } var toolbar = APP.toolbar = Toolbar.create(configTb);