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);
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);

@ -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;

@ -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,10 +59,12 @@ define([
var uri = ['', 'blob', id.slice(0,2), id].join('/');
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();
});
});
};
common.uploadStatus(teamId, estimate, function (e, pending) {

@ -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}); }

Loading…
Cancel
Save