Improve blob cache

pull/1/head
yflory 4 years ago
parent 82c869f4cd
commit d4055f6ef5

@ -8,15 +8,15 @@ define([
var e = err || (data && data.error); var e = err || (data && data.error);
if (e) { return void cb(e); } if (e) { return void cb(e); }
if (!data || typeof(data) !== "object") { return void cb('EINVAL'); } if (!data || typeof(data) !== "object") { return void cb('EINVAL'); }
var arr = Object.keys(data).map(function (i) { return data[i]; }); var u8 = Uint8Array.from(data);
var u8 = Uint8Array.from(arr);
cb(null, u8); cb(null, u8);
}); });
}; };
var setBlobCache = function (id, u8, cb) { var setBlobCache = function (id, u8, cb) {
var array = [].slice.call(u8);
sframeChan.query('Q_SET_BLOB_CACHE', { sframeChan.query('Q_SET_BLOB_CACHE', {
id: id, id: id,
u8: u8 u8: array
}, function (err, data) { }, function (err, data) {
var e = err || (data && data.error) || undefined; var e = err || (data && data.error) || undefined;
cb(e); cb(e);

@ -24,8 +24,8 @@ define([
}); });
Messages.mediatag_saveButton = "Save"; // XXX Messages.mediatag_saveButton = "Save"; // XXX
MediaTag.setDefaultConfig('download', { MediaTag.setDefaultConfig('download', {
text: Messages.download_mt_button, text: Messages.mediatag_saveButton,
textDl: Messages.mediatag_saveButton textDl: Messages.download_mt_button,
}); });
} }
MT.MediaTag = MediaTag; MT.MediaTag = MediaTag;

@ -1,9 +1,11 @@
define([ define([
'/file/file-crypto.js', '/file/file-crypto.js',
'/common/common-hash.js', '/common/common-hash.js',
'/common/common-util.js',
'/common/outer/cache-store.js',
'/bower_components/nthen/index.js', '/bower_components/nthen/index.js',
'/bower_components/tweetnacl/nacl-fast.min.js', '/bower_components/tweetnacl/nacl-fast.min.js',
], function (FileCrypto, Hash, nThen) { ], function (FileCrypto, Hash, Util, Cache, nThen) {
var Nacl = window.nacl; var Nacl = window.nacl;
var module = {}; var module = {};
@ -31,9 +33,11 @@ define([
}; };
var actual = 0; var actual = 0;
var encryptedArr = [];;
var again = function (err, box) { var again = function (err, box) {
if (err) { onError(err); } if (err) { onError(err); }
if (box) { if (box) {
encryptedArr.push(box);
actual += box.length; actual += box.length;
var progressValue = (actual / estimate * 100); var progressValue = (actual / estimate * 100);
progressValue = Math.min(progressValue, 100); progressValue = Math.min(progressValue, 100);
@ -55,10 +59,12 @@ define([
var uri = ['', 'blob', id.slice(0,2), id].join('/'); var uri = ['', 'blob', id.slice(0,2), id].join('/');
console.log("encrypted blob is now available as %s", uri); console.log("encrypted blob is now available as %s", uri);
var box_u8 = Util.uint8ArrayJoin(encryptedArr);
Cache.setBlobCache(id, box_u8, function (err) {
if (err) { console.warn(err); }
cb(); cb();
}); });
});
}; };
common.uploadStatus(teamId, estimate, function (e, pending) { common.uploadStatus(teamId, estimate, function (e, pending) {

@ -683,12 +683,13 @@ define([
sframeChan.on('Q_GET_BLOB_CACHE', function (data, cb) { sframeChan.on('Q_GET_BLOB_CACHE', function (data, cb) {
Utils.Cache.getBlobCache(data.id, function (err, obj) { Utils.Cache.getBlobCache(data.id, function (err, obj) {
if (err) { return void cb({error: err}); } if (err) { return void cb({error: err}); }
cb(obj); var arr = [].slice.call(obj);
cb(arr);
}); });
}); });
sframeChan.on('Q_SET_BLOB_CACHE', function (data, cb) { sframeChan.on('Q_SET_BLOB_CACHE', function (data, cb) {
if (!data || !data.u8 || typeof(data.u8) !== "object") { return void cb({error: 'EINVAL'}); } if (!data || !data.u8 || typeof(data.u8) !== "object") { return void cb({error: 'EINVAL'}); }
var arr = Object.keys(data.u8).map(function (i) { return data.u8[i]; }); var arr = data.u8;
var u8 = Uint8Array.from(arr); var u8 = Uint8Array.from(arr);
Utils.Cache.setBlobCache(data.id, u8, function (err) { Utils.Cache.setBlobCache(data.id, u8, function (err) {
if (err) { return void cb({error: err}); } if (err) { return void cb({error: err}); }

Loading…
Cancel
Save