|
|
@ -7,6 +7,82 @@ define([
|
|
|
|
var Nacl = window.nacl;
|
|
|
|
var Nacl = window.nacl;
|
|
|
|
var module = {};
|
|
|
|
var module = {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.uploadU8 =function (common, data, cb) {
|
|
|
|
|
|
|
|
var teamId = data.teamId;
|
|
|
|
|
|
|
|
var u8 = data.u8;
|
|
|
|
|
|
|
|
var metadata = data.metadata;
|
|
|
|
|
|
|
|
var key = data.key;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var onError = data.onError || function () {};
|
|
|
|
|
|
|
|
var onPending = data.onPending || function () {};
|
|
|
|
|
|
|
|
var updateProgress = data.updateProgress || function () {};
|
|
|
|
|
|
|
|
var owned = data.owned;
|
|
|
|
|
|
|
|
var id = data.id;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var next = FileCrypto.encrypt(u8, metadata, key);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var estimate = FileCrypto.computeEncryptedSize(u8.length, metadata);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var sendChunk = function (box, cb) {
|
|
|
|
|
|
|
|
var enc = Nacl.util.encodeBase64(box);
|
|
|
|
|
|
|
|
common.uploadChunk(teamId, enc, function (e, msg) {
|
|
|
|
|
|
|
|
cb(e, msg);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var actual = 0;
|
|
|
|
|
|
|
|
var again = function (err, box) {
|
|
|
|
|
|
|
|
if (err) { onError(err); }
|
|
|
|
|
|
|
|
if (box) {
|
|
|
|
|
|
|
|
actual += box.length;
|
|
|
|
|
|
|
|
var progressValue = (actual / estimate * 100);
|
|
|
|
|
|
|
|
progressValue = Math.min(progressValue, 100);
|
|
|
|
|
|
|
|
updateProgress(progressValue);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return void sendChunk(box, function (e) {
|
|
|
|
|
|
|
|
if (e) { return console.error(e); }
|
|
|
|
|
|
|
|
next(again);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (actual !== estimate) {
|
|
|
|
|
|
|
|
console.error('Estimated size does not match actual size');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if not box then done
|
|
|
|
|
|
|
|
common.uploadComplete(teamId, id, owned, function (e) {
|
|
|
|
|
|
|
|
if (e) { return void console.error(e); }
|
|
|
|
|
|
|
|
var uri = ['', 'blob', id.slice(0,2), id].join('/');
|
|
|
|
|
|
|
|
console.log("encrypted blob is now available as %s", uri);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cb();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
common.uploadStatus(teamId, estimate, function (e, pending) {
|
|
|
|
|
|
|
|
if (e) {
|
|
|
|
|
|
|
|
console.error(e);
|
|
|
|
|
|
|
|
onError(e);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (pending) {
|
|
|
|
|
|
|
|
return void onPending(function () {
|
|
|
|
|
|
|
|
// if the user wants to cancel the pending upload to execute that one
|
|
|
|
|
|
|
|
common.uploadCancel(teamId, estimate, function (e) {
|
|
|
|
|
|
|
|
if (e) {
|
|
|
|
|
|
|
|
return void console.error(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
next(again);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
next(again);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
module.upload = function (file, noStore, common, updateProgress, onComplete, onError, onPending) {
|
|
|
|
module.upload = function (file, noStore, common, updateProgress, onComplete, onError, onPending) {
|
|
|
|
var u8 = file.blob; // This is not a blob but a uint8array
|
|
|
|
var u8 = file.blob; // This is not a blob but a uint8array
|
|
|
|
var metadata = file.metadata;
|
|
|
|
var metadata = file.metadata;
|
|
|
@ -50,85 +126,36 @@ define([
|
|
|
|
metadata.owners = [edPublic];
|
|
|
|
metadata.owners = [edPublic];
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}).nThen(function () {
|
|
|
|
}).nThen(function () {
|
|
|
|
var next = FileCrypto.encrypt(u8, metadata, key);
|
|
|
|
module.uploadU8(common, {
|
|
|
|
|
|
|
|
teamId: teamId,
|
|
|
|
var estimate = FileCrypto.computeEncryptedSize(u8.length, metadata);
|
|
|
|
u8: u8,
|
|
|
|
|
|
|
|
metadata: metadata,
|
|
|
|
var sendChunk = function (box, cb) {
|
|
|
|
key: key,
|
|
|
|
var enc = Nacl.util.encodeBase64(box);
|
|
|
|
id: id,
|
|
|
|
common.uploadChunk(teamId, enc, function (e, msg) {
|
|
|
|
owned: owned,
|
|
|
|
cb(e, msg);
|
|
|
|
onError: onError,
|
|
|
|
});
|
|
|
|
onPending: onPending,
|
|
|
|
};
|
|
|
|
updateProgress: updateProgress,
|
|
|
|
|
|
|
|
}, function () {
|
|
|
|
var actual = 0;
|
|
|
|
if (noStore) { return void onComplete(href); }
|
|
|
|
var again = function (err, box) {
|
|
|
|
|
|
|
|
if (err) { throw new Error(err); }
|
|
|
|
var title = metadata.name;
|
|
|
|
if (box) {
|
|
|
|
var data = {
|
|
|
|
actual += box.length;
|
|
|
|
teamId: teamId,
|
|
|
|
var progressValue = (actual / estimate * 100);
|
|
|
|
title: title || "",
|
|
|
|
progressValue = Math.min(progressValue, 100);
|
|
|
|
href: href,
|
|
|
|
updateProgress(progressValue);
|
|
|
|
path: path,
|
|
|
|
|
|
|
|
password: password,
|
|
|
|
return void sendChunk(box, function (e) {
|
|
|
|
channel: id,
|
|
|
|
if (e) { return console.error(e); }
|
|
|
|
owners: metadata.owners,
|
|
|
|
next(again);
|
|
|
|
forceSave: forceSave
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
common.setPadTitle(data, function (err) {
|
|
|
|
|
|
|
|
if (err) { return void console.error(err); }
|
|
|
|
if (actual !== estimate) {
|
|
|
|
onComplete(href);
|
|
|
|
console.error('Estimated size does not match actual size');
|
|
|
|
common.setPadAttribute('fileType', metadata.type, null, href);
|
|
|
|
}
|
|
|
|
common.setPadAttribute('owners', metadata.owners, null, href);
|
|
|
|
|
|
|
|
|
|
|
|
// if not box then done
|
|
|
|
|
|
|
|
common.uploadComplete(teamId, id, owned, function (e) {
|
|
|
|
|
|
|
|
if (e) { return void console.error(e); }
|
|
|
|
|
|
|
|
var uri = ['', 'blob', id.slice(0,2), id].join('/');
|
|
|
|
|
|
|
|
console.log("encrypted blob is now available as %s", uri);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var title = metadata.name;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (noStore) { return void onComplete(href); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
|
|
|
|
teamId: teamId,
|
|
|
|
|
|
|
|
title: title || "",
|
|
|
|
|
|
|
|
href: href,
|
|
|
|
|
|
|
|
path: path,
|
|
|
|
|
|
|
|
password: password,
|
|
|
|
|
|
|
|
channel: id,
|
|
|
|
|
|
|
|
owners: metadata.owners,
|
|
|
|
|
|
|
|
forceSave: forceSave
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
common.setPadTitle(data, function (err) {
|
|
|
|
|
|
|
|
if (err) { return void console.error(err); }
|
|
|
|
|
|
|
|
onComplete(href);
|
|
|
|
|
|
|
|
common.setPadAttribute('fileType', metadata.type, null, href);
|
|
|
|
|
|
|
|
common.setPadAttribute('owners', metadata.owners, null, href);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
common.uploadStatus(teamId, estimate, function (e, pending) {
|
|
|
|
|
|
|
|
if (e) {
|
|
|
|
|
|
|
|
console.error(e);
|
|
|
|
|
|
|
|
onError(e);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (pending) {
|
|
|
|
|
|
|
|
return void onPending(function () {
|
|
|
|
|
|
|
|
// if the user wants to cancel the pending upload to execute that one
|
|
|
|
|
|
|
|
common.uploadCancel(teamId, estimate, function (e) {
|
|
|
|
|
|
|
|
if (e) {
|
|
|
|
|
|
|
|
return void console.error(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
next(again);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
next(again);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|