Fix thumbnails in sframe apps

pull/1/head
yflory 7 years ago
parent 888028c542
commit aa744567ed

@ -76,6 +76,7 @@ define([
common.renamePad(title || "", href, function (err) { common.renamePad(title || "", href, function (err) {
if (err) { return void console.error(err); } if (err) { return void console.error(err); }
onComplete(href); onComplete(href);
common.setPadAttribute('fileType', metadata.type, null, href);
}); });
}); });
}; };

@ -489,8 +489,8 @@ define([
}; };
// STORAGE // STORAGE
common.setPadAttribute = function (attr, value, cb) { common.setPadAttribute = function (attr, value, cb, href) {
var href = getRelativeHref(window.location.href); href = getRelativeHref(href || window.location.href);
getStore().setPadAttribute(href, attr, value, cb); getStore().setPadAttribute(href, attr, value, cb);
}; };
common.setDisplayName = function (value, cb) { common.setDisplayName = function (value, cb) {

@ -1,8 +1,9 @@
define([ define([
'jquery', 'jquery',
'/file/file-crypto.js', '/file/file-crypto.js',
'/common/common-thumbnail.js',
'/bower_components/tweetnacl/nacl-fast.min.js', '/bower_components/tweetnacl/nacl-fast.min.js',
], function ($, FileCrypto) { ], function ($, FileCrypto, Thumb) {
var Nacl = window.nacl; var Nacl = window.nacl;
var module = {}; var module = {};
@ -220,30 +221,46 @@ define([
var handleFile = File.handleFile = function (file, e, thumbnail) { var handleFile = File.handleFile = function (file, e, thumbnail) {
var thumb; var thumb;
var finish = function (arrayBuffer) { var file_arraybuffer;
var finish = function () {
var metadata = { var metadata = {
name: file.name, name: file.name,
type: file.type, type: file.type,
}; };
if (thumb) { metadata.thumbnail = thumb; } if (thumb) { metadata.thumbnail = thumb; }
queue.push({ queue.push({
blob: arrayBuffer, blob: file_arraybuffer,
metadata: metadata, metadata: metadata,
dropEvent: e dropEvent: e
}); });
}; };
var processFile = function () {
blobToArrayBuffer(file, function (e, buffer) { blobToArrayBuffer(file, function (e, buffer) {
finish(buffer); if (e) { console.error(e); }
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 (!thumbnail) { return void processFile(); } if (!Thumb.isSupportedType(file.type)) { return finish(); }
blobToArrayBuffer(thumbnail, function (e, buffer) { // make a resized thumbnail from the image..
Thumb.fromImageBlob(file, function (e, thumb_blob) {
if (e) { console.error(e); } 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); thumb = arrayBufferToString(buffer);
processFile(); finish();
});
});
}); });
}; };

@ -77,7 +77,7 @@ define([
sfCommon: common, sfCommon: common,
}; };
if (uploadMode) { if (uploadMode) {
displayed.push('pageTitle'); //TODO in toolbar displayed.push('pageTitle');
configTb.pageTitle = Messages.upload_title; configTb.pageTitle = Messages.upload_title;
} }
var toolbar = APP.toolbar = Toolbar.create(configTb); var toolbar = APP.toolbar = Toolbar.create(configTb);

Loading…
Cancel
Save