|
|
@ -53,9 +53,6 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
var _downloadFile = function (ctx, fData, cb, updateProgress) {
|
|
|
|
var _downloadFile = function (ctx, fData, cb, updateProgress) {
|
|
|
|
var cancelled = false;
|
|
|
|
var cancelled = false;
|
|
|
|
var cancel = function () {
|
|
|
|
|
|
|
|
cancelled = true;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
var href = (fData.href && fData.href.indexOf('#') !== -1) ? fData.href : fData.roHref;
|
|
|
|
var href = (fData.href && fData.href.indexOf('#') !== -1) ? fData.href : fData.roHref;
|
|
|
|
var parsed = Hash.parsePadUrl(href);
|
|
|
|
var parsed = Hash.parsePadUrl(href);
|
|
|
|
var hash = parsed.hash;
|
|
|
|
var hash = parsed.hash;
|
|
|
@ -63,10 +60,13 @@ define([
|
|
|
|
var secret = Hash.getSecrets('file', hash, fData.password);
|
|
|
|
var secret = Hash.getSecrets('file', hash, fData.password);
|
|
|
|
var src = (ctx.fileHost || '') + Hash.getBlobPathFromHex(secret.channel);
|
|
|
|
var src = (ctx.fileHost || '') + Hash.getBlobPathFromHex(secret.channel);
|
|
|
|
var key = secret.keys && secret.keys.cryptKey;
|
|
|
|
var key = secret.keys && secret.keys.cryptKey;
|
|
|
|
Util.fetch(src, function (err, u8) {
|
|
|
|
|
|
|
|
|
|
|
|
var fetchObj, decryptObj;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fetchObj = Util.fetch(src, function (err, u8) {
|
|
|
|
if (cancelled) { return; }
|
|
|
|
if (cancelled) { return; }
|
|
|
|
if (err) { return void cb('E404'); }
|
|
|
|
if (err) { return void cb('E404'); }
|
|
|
|
FileCrypto.decrypt(u8, key, function (err, res) {
|
|
|
|
decryptObj = FileCrypto.decrypt(u8, key, function (err, res) {
|
|
|
|
if (cancelled) { return; }
|
|
|
|
if (cancelled) { return; }
|
|
|
|
if (err) { return void cb(err); }
|
|
|
|
if (err) { return void cb(err); }
|
|
|
|
if (!res.content) { return void cb('EEMPTY'); }
|
|
|
|
if (!res.content) { return void cb('EEMPTY'); }
|
|
|
@ -78,8 +78,25 @@ define([
|
|
|
|
content: res.content,
|
|
|
|
content: res.content,
|
|
|
|
download: dl
|
|
|
|
download: dl
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}, updateProgress && updateProgress.progress2);
|
|
|
|
}, function (data) {
|
|
|
|
}, updateProgress && updateProgress.progress);
|
|
|
|
if (cancelled) { return; }
|
|
|
|
|
|
|
|
if (updateProgress && updateProgress.progress2) {
|
|
|
|
|
|
|
|
updateProgress.progress2(data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}, function (data) {
|
|
|
|
|
|
|
|
if (cancelled) { return; }
|
|
|
|
|
|
|
|
if (updateProgress && updateProgress.progress) {
|
|
|
|
|
|
|
|
updateProgress.progress(data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var cancel = function () {
|
|
|
|
|
|
|
|
cancelled = true;
|
|
|
|
|
|
|
|
if (fetchObj && fetchObj.cancel) { fetchObj.cancel(); }
|
|
|
|
|
|
|
|
if (decryptObj && decryptObj.cancel) { decryptObj.cancel(); }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
cancel: cancel
|
|
|
|
cancel: cancel
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -162,10 +179,10 @@ define([
|
|
|
|
if (ctx.stop) { return; }
|
|
|
|
if (ctx.stop) { return; }
|
|
|
|
if (to) { clearTimeout(to); }
|
|
|
|
if (to) { clearTimeout(to); }
|
|
|
|
//setTimeout(g, 2000);
|
|
|
|
//setTimeout(g, 2000);
|
|
|
|
g();
|
|
|
|
|
|
|
|
w();
|
|
|
|
|
|
|
|
ctx.done++;
|
|
|
|
ctx.done++;
|
|
|
|
ctx.updateProgress('download', {max: ctx.max, current: ctx.done});
|
|
|
|
ctx.updateProgress('download', {max: ctx.max, current: ctx.done});
|
|
|
|
|
|
|
|
g();
|
|
|
|
|
|
|
|
w();
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var error = function (err) {
|
|
|
|
var error = function (err) {
|
|
|
@ -312,13 +329,14 @@ define([
|
|
|
|
delete ctx.zip;
|
|
|
|
delete ctx.zip;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
return {
|
|
|
|
return {
|
|
|
|
stop: stop
|
|
|
|
stop: stop,
|
|
|
|
|
|
|
|
cancel: stop
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var _downloadFolder = function (ctx, data, cb, updateProgress) {
|
|
|
|
var _downloadFolder = function (ctx, data, cb, updateProgress) {
|
|
|
|
create(data, ctx.get, ctx.fileHost, function (blob, errors) {
|
|
|
|
return create(data, ctx.get, ctx.fileHost, function (blob, errors) {
|
|
|
|
if (errors && errors.length) { console.error(errors); } // TODO show user errors
|
|
|
|
if (errors && errors.length) { console.error(errors); } // TODO show user errors
|
|
|
|
var dl = function () {
|
|
|
|
var dl = function () {
|
|
|
|
saveAs(blob, data.folderName);
|
|
|
|
saveAs(blob, data.folderName);
|
|
|
@ -332,8 +350,11 @@ define([
|
|
|
|
if (typeof progress.current !== "number") { return; }
|
|
|
|
if (typeof progress.current !== "number") { return; }
|
|
|
|
updateProgress.folderProgress(progress.current / progress.max);
|
|
|
|
updateProgress.folderProgress(progress.current / progress.max);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (state === "compressing") {
|
|
|
|
|
|
|
|
updateProgress.folderProgress(2);
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (state === "done") {
|
|
|
|
else if (state === "done") {
|
|
|
|
updateProgress.folderProgress(1);
|
|
|
|
updateProgress.folderProgress(3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|