Improve blob cache

This commit is contained in:
yflory 2020-11-30 14:40:07 +01:00
parent 82c869f4cd
commit d4055f6ef5
4 changed files with 18 additions and 11 deletions

View file

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

View file

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

View file

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

View file

@ -683,12 +683,13 @@ define([
sframeChan.on('Q_GET_BLOB_CACHE', function (data, cb) {
Utils.Cache.getBlobCache(data.id, function (err, obj) {
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) {
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);
Utils.Cache.setBlobCache(data.id, u8, function (err) {
if (err) { return void cb({error: err}); }