|
|
@ -4,9 +4,8 @@ define([
|
|
|
|
'/common/visible.js',
|
|
|
|
'/common/visible.js',
|
|
|
|
'/common/common-hash.js',
|
|
|
|
'/common/common-hash.js',
|
|
|
|
'/file/file-crypto.js',
|
|
|
|
'/file/file-crypto.js',
|
|
|
|
'/bower_components/localforage/dist/localforage.min.js',
|
|
|
|
|
|
|
|
'/bower_components/tweetnacl/nacl-fast.min.js',
|
|
|
|
'/bower_components/tweetnacl/nacl-fast.min.js',
|
|
|
|
], function ($, Util, Visible, Hash, FileCrypto, localForage) {
|
|
|
|
], function ($, Util, Visible, Hash, FileCrypto) {
|
|
|
|
var Nacl = window.nacl;
|
|
|
|
var Nacl = window.nacl;
|
|
|
|
var Thumb = {
|
|
|
|
var Thumb = {
|
|
|
|
dimension: 100,
|
|
|
|
dimension: 100,
|
|
|
@ -196,7 +195,7 @@ define([
|
|
|
|
require(['/bower_components/html2canvas/build/html2canvas.min.js'], todo);
|
|
|
|
require(['/bower_components/html2canvas/build/html2canvas.min.js'], todo);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Thumb.initPadThumbnails = function (opts) {
|
|
|
|
Thumb.initPadThumbnails = function (common, opts) {
|
|
|
|
if (!opts.href || !opts.getContent) {
|
|
|
|
if (!opts.href || !opts.getContent) {
|
|
|
|
throw new Error("href and getContent are needed for thumbnails");
|
|
|
|
throw new Error("href and getContent are needed for thumbnails");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -206,7 +205,7 @@ define([
|
|
|
|
if (content === oldThumbnailState) { return; }
|
|
|
|
if (content === oldThumbnailState) { return; }
|
|
|
|
Thumb.fromDOM(opts, function (err, b64) {
|
|
|
|
Thumb.fromDOM(opts, function (err, b64) {
|
|
|
|
oldThumbnailState = content;
|
|
|
|
oldThumbnailState = content;
|
|
|
|
Thumb.setPadThumbnail(opts.href, b64);
|
|
|
|
Thumb.setPadThumbnail(common, opts.href, b64);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
var nafa = Util.notAgainForAnother(mkThumbnail, Thumb.UPDATE_INTERVAL);
|
|
|
|
var nafa = Util.notAgainForAnother(mkThumbnail, Thumb.UPDATE_INTERVAL);
|
|
|
@ -238,15 +237,19 @@ define([
|
|
|
|
$span.prepend(img);
|
|
|
|
$span.prepend(img);
|
|
|
|
cb($(img));
|
|
|
|
cb($(img));
|
|
|
|
};
|
|
|
|
};
|
|
|
|
Thumb.setPadThumbnail = function (href, b64, cb) {
|
|
|
|
var getKey = function (href) {
|
|
|
|
|
|
|
|
var parsed = Hash.parsePadUrl(href);
|
|
|
|
|
|
|
|
return 'thumbnail-' + parsed.type + '-' + parsed.hashData.channel;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
Thumb.setPadThumbnail = function (common, href, b64, cb) {
|
|
|
|
cb = cb || function () {};
|
|
|
|
cb = cb || function () {};
|
|
|
|
var k ='thumbnail-' + href;
|
|
|
|
var k = getKey(href);
|
|
|
|
localForage.setItem(k, b64, cb);
|
|
|
|
common.setThumbnail(k, b64, cb);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
Thumb.displayThumbnail = function (href, $container, cb) {
|
|
|
|
Thumb.displayThumbnail = function (common, href, $container, cb) {
|
|
|
|
cb = cb || function () {};
|
|
|
|
cb = cb || function () {};
|
|
|
|
var parsed = Hash.parsePadUrl(href);
|
|
|
|
var parsed = Hash.parsePadUrl(href);
|
|
|
|
var k ='thumbnail-' + href;
|
|
|
|
var k = getKey(href);
|
|
|
|
var whenNewThumb = function () {
|
|
|
|
var whenNewThumb = function () {
|
|
|
|
var secret = Hash.getSecrets('file', parsed.hash);
|
|
|
|
var secret = Hash.getSecrets('file', parsed.hash);
|
|
|
|
var hexFileName = Util.base64ToHex(secret.channel);
|
|
|
|
var hexFileName = Util.base64ToHex(secret.channel);
|
|
|
@ -254,15 +257,17 @@ define([
|
|
|
|
var cryptKey = secret.keys && secret.keys.fileKeyStr;
|
|
|
|
var cryptKey = secret.keys && secret.keys.fileKeyStr;
|
|
|
|
var key = Nacl.util.decodeBase64(cryptKey);
|
|
|
|
var key = Nacl.util.decodeBase64(cryptKey);
|
|
|
|
FileCrypto.fetchDecryptedMetadata(src, key, function (e, metadata) {
|
|
|
|
FileCrypto.fetchDecryptedMetadata(src, key, function (e, metadata) {
|
|
|
|
if (!metadata.thumbnail) {
|
|
|
|
var v = metadata.thumbnail;
|
|
|
|
return void localForage.setItem(k, 'EMPTY');
|
|
|
|
if (!v) {
|
|
|
|
|
|
|
|
v = 'EMPTY';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
localForage.setItem(k, metadata.thumbnail, function (err) {
|
|
|
|
Thumb.setPadThumbnail(common, href, v, function (err) {
|
|
|
|
|
|
|
|
if (!metadata.thumbnail) { return; }
|
|
|
|
addThumbnail(err, metadata.thumbnail, $container, cb);
|
|
|
|
addThumbnail(err, metadata.thumbnail, $container, cb);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
localForage.getItem(k, function (err, v) {
|
|
|
|
common.getThumbnail(k, function (err, v) {
|
|
|
|
if (!v && parsed.type === 'file') {
|
|
|
|
if (!v && parsed.type === 'file') {
|
|
|
|
// We can only create thumbnails for files here since we can't easily decrypt pads
|
|
|
|
// We can only create thumbnails for files here since we can't easily decrypt pads
|
|
|
|
return void whenNewThumb();
|
|
|
|
return void whenNewThumb();
|
|
|
|