Upload owned files
This commit is contained in:
@@ -230,9 +230,18 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
Store.uploadComplete = function (id, cb) {
|
||||
Store.uploadComplete = function (data, cb) {
|
||||
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
|
||||
store.rpc.uploadComplete(id, function (err, res) {
|
||||
if (data.owned) {
|
||||
// Owned file
|
||||
store.rpc.ownedUploadComplete(data.id, function (err, res) {
|
||||
if (err) { return void cb({error:err}); }
|
||||
cb(res);
|
||||
});
|
||||
return;
|
||||
}
|
||||
// Normal upload
|
||||
store.rpc.uploadComplete(data.id, function (err, res) {
|
||||
if (err) { return void cb({error:err}); }
|
||||
cb(res);
|
||||
});
|
||||
@@ -678,6 +687,7 @@ define([
|
||||
if (Store.channel && Store.channel.wc && channel === Store.channel.wc.id) {
|
||||
owners = Store.channel.data.owners || undefined;
|
||||
}
|
||||
|
||||
var expire;
|
||||
if (Store.channel && Store.channel.wc && channel === Store.channel.wc.id) {
|
||||
expire = +Store.channel.data.expire || undefined;
|
||||
@@ -726,7 +736,11 @@ define([
|
||||
contains = true;
|
||||
pad.atime = +new Date();
|
||||
pad.title = title;
|
||||
pad.owners = owners;
|
||||
if (owners || h.type !== "file") {
|
||||
// OWNED_FILES
|
||||
// Never remove owner for files
|
||||
pad.owners = owners;
|
||||
}
|
||||
pad.expire = expire;
|
||||
|
||||
// If the href is different, it means we have a stronger one
|
||||
|
||||
@@ -11,6 +11,10 @@ define([
|
||||
var u8 = file.blob; // This is not a blob but a uint8array
|
||||
var metadata = file.metadata;
|
||||
|
||||
var owned = file.isOwned;
|
||||
// XXX
|
||||
owned = true;
|
||||
|
||||
// if it exists, path contains the new pad location in the drive
|
||||
var path = file.path;
|
||||
|
||||
@@ -34,9 +38,16 @@ define([
|
||||
});
|
||||
};
|
||||
|
||||
var edPublic;
|
||||
nThen(function (waitFor) {
|
||||
// Generate a hash and check if the resulting id is valid (not already used)
|
||||
getValidHash(waitFor());
|
||||
}).nThen(function (waitFor) {
|
||||
if (!owned) { return; }
|
||||
common.getMetadata(waitFor(function (err, m) {
|
||||
edPublic = m.priv.edPublic;
|
||||
metadata.owners = [edPublic];
|
||||
}));
|
||||
}).nThen(function () {
|
||||
var next = FileCrypto.encrypt(u8, metadata, key);
|
||||
|
||||
@@ -68,7 +79,7 @@ define([
|
||||
}
|
||||
|
||||
// if not box then done
|
||||
common.uploadComplete(id, function (e) {
|
||||
common.uploadComplete(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);
|
||||
@@ -89,6 +100,7 @@ define([
|
||||
if (err) { return void console.error(err); }
|
||||
onComplete(href);
|
||||
common.setPadAttribute('fileType', metadata.type, null, href);
|
||||
common.setPadAttribute('owners', metadata.owners, null, href);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user