Refactoring part2
This commit is contained in:
parent
7222d34dc0
commit
4c339afc6c
@ -110,6 +110,14 @@ define([
|
|||||||
data: data
|
data: data
|
||||||
}, cb);
|
}, cb);
|
||||||
};
|
};
|
||||||
|
common.getEdPublic = function (teamId, cb) {
|
||||||
|
postMessage("GET", {
|
||||||
|
teamId: teamId,
|
||||||
|
key: ['edPublic']
|
||||||
|
}, function (obj) {
|
||||||
|
cb(obj);
|
||||||
|
});
|
||||||
|
};
|
||||||
// Settings and ready
|
// Settings and ready
|
||||||
common.mergeAnonDrive = function (cb) {
|
common.mergeAnonDrive = function (cb) {
|
||||||
var data = {
|
var data = {
|
||||||
@ -259,11 +267,8 @@ define([
|
|||||||
postMessage("CLEAR_OWNED_CHANNEL", channel, cb);
|
postMessage("CLEAR_OWNED_CHANNEL", channel, cb);
|
||||||
};
|
};
|
||||||
// "force" allows you to delete your drive ID
|
// "force" allows you to delete your drive ID
|
||||||
common.removeOwnedChannel = function (channel, cb, force) {
|
common.removeOwnedChannel = function (data, cb) {
|
||||||
postMessage("REMOVE_OWNED_CHANNEL", {
|
postMessage("REMOVE_OWNED_CHANNEL", data, cb);
|
||||||
channel: channel,
|
|
||||||
force: force
|
|
||||||
}, cb);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
common.getDeletedPads = function (data, cb) {
|
common.getDeletedPads = function (data, cb) {
|
||||||
@ -273,29 +278,29 @@ define([
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
common.uploadComplete = function (id, owned, cb) {
|
common.uploadComplete = function (teamId, id, owned, cb) {
|
||||||
postMessage("UPLOAD_COMPLETE", {id: id, owned: owned}, function (obj) {
|
postMessage("UPLOAD_COMPLETE", {teamId: teamId, id: id, owned: owned}, function (obj) {
|
||||||
if (obj && obj.error) { return void cb(obj.error); }
|
if (obj && obj.error) { return void cb(obj.error); }
|
||||||
cb(null, obj);
|
cb(null, obj);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
common.uploadStatus = function (size, cb) {
|
common.uploadStatus = function (teamId, size, cb) {
|
||||||
postMessage("UPLOAD_STATUS", {size: size}, function (obj) {
|
postMessage("UPLOAD_STATUS", {teamId: teamId, size: size}, function (obj) {
|
||||||
if (obj && obj.error) { return void cb(obj.error); }
|
if (obj && obj.error) { return void cb(obj.error); }
|
||||||
cb(null, obj);
|
cb(null, obj);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
common.uploadCancel = function (size, cb) {
|
common.uploadCancel = function (teamId, size, cb) {
|
||||||
postMessage("UPLOAD_CANCEL", {size: size}, function (obj) {
|
postMessage("UPLOAD_CANCEL", {teamId: teamId, size: size}, function (obj) {
|
||||||
if (obj && obj.error) { return void cb(obj.error); }
|
if (obj && obj.error) { return void cb(obj.error); }
|
||||||
cb(null, obj);
|
cb(null, obj);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
common.uploadChunk = function (data, cb) {
|
common.uploadChunk = function (teamId, data, cb) {
|
||||||
postMessage("UPLOAD_CHUNK", {chunk: data}, function (obj) {
|
postMessage("UPLOAD_CHUNK", {teamId: teamId, chunk: data}, function (obj) {
|
||||||
if (obj && obj.error) { return void cb(obj.error); }
|
if (obj && obj.error) { return void cb(obj.error); }
|
||||||
cb(null, obj);
|
cb(null, obj);
|
||||||
});
|
});
|
||||||
@ -496,6 +501,7 @@ define([
|
|||||||
Cryptput(hash, data.toSave, function (e) {
|
Cryptput(hash, data.toSave, function (e) {
|
||||||
if (e) { throw new Error(e); }
|
if (e) { throw new Error(e); }
|
||||||
postMessage("ADD_PAD", {
|
postMessage("ADD_PAD", {
|
||||||
|
teamId: data.teamId,
|
||||||
href: href,
|
href: href,
|
||||||
title: data.title,
|
title: data.title,
|
||||||
path: ['template']
|
path: ['template']
|
||||||
@ -784,6 +790,7 @@ define([
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// XXX Teams: change the password of a pad owned by the team
|
||||||
common.changePadPassword = function (Crypt, href, newPassword, edPublic, cb) {
|
common.changePadPassword = function (Crypt, href, newPassword, edPublic, cb) {
|
||||||
if (!href) { return void cb({ error: 'EINVAL_HREF' }); }
|
if (!href) { return void cb({ error: 'EINVAL_HREF' }); }
|
||||||
var parsed = Hash.parsePadUrl(href);
|
var parsed = Hash.parsePadUrl(href);
|
||||||
@ -850,7 +857,10 @@ define([
|
|||||||
}, waitFor());
|
}, waitFor());
|
||||||
pad.onDisconnectEvent.fire(true);
|
pad.onDisconnectEvent.fire(true);
|
||||||
}).nThen(function (waitFor) {
|
}).nThen(function (waitFor) {
|
||||||
common.removeOwnedChannel(oldChannel, waitFor(function (obj) {
|
common.removeOwnedChannel({
|
||||||
|
channel: oldChannel,
|
||||||
|
teamId: null // TODO
|
||||||
|
}, waitFor(function (obj) {
|
||||||
if (obj && obj.error) {
|
if (obj && obj.error) {
|
||||||
waitFor.abort();
|
waitFor.abort();
|
||||||
return void cb(obj);
|
return void cb(obj);
|
||||||
@ -1027,7 +1037,11 @@ define([
|
|||||||
}).nThen(function (waitFor) {
|
}).nThen(function (waitFor) {
|
||||||
if (oldIsOwned) {
|
if (oldIsOwned) {
|
||||||
console.log('removing old drive');
|
console.log('removing old drive');
|
||||||
common.removeOwnedChannel(secret.channel, waitFor(function (obj) {
|
common.removeOwnedChannel({
|
||||||
|
channel: secret.channel,
|
||||||
|
teamId: null,
|
||||||
|
force: true
|
||||||
|
}, waitFor(function (obj) {
|
||||||
if (obj && obj.error) {
|
if (obj && obj.error) {
|
||||||
// Deal with it as if it was not owned
|
// Deal with it as if it was not owned
|
||||||
oldIsOwned = false;
|
oldIsOwned = false;
|
||||||
@ -1036,7 +1050,7 @@ define([
|
|||||||
common.logoutFromAll(waitFor(function () {
|
common.logoutFromAll(waitFor(function () {
|
||||||
postMessage("DISCONNECT");
|
postMessage("DISCONNECT");
|
||||||
}));
|
}));
|
||||||
}), true);
|
}));
|
||||||
}
|
}
|
||||||
}).nThen(function (waitFor) {
|
}).nThen(function (waitFor) {
|
||||||
if (!oldIsOwned) {
|
if (!oldIsOwned) {
|
||||||
|
|||||||
@ -146,14 +146,12 @@ define([
|
|||||||
onSync(data.teamId, cb);
|
onSync(data.teamId, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
// XXX Teams
|
|
||||||
Store.hasSigningKeys = function () {
|
Store.hasSigningKeys = function () {
|
||||||
if (!store.proxy) { return; }
|
if (!store.proxy) { return; }
|
||||||
return typeof(store.proxy.edPrivate) === 'string' &&
|
return typeof(store.proxy.edPrivate) === 'string' &&
|
||||||
typeof(store.proxy.edPublic) === 'string';
|
typeof(store.proxy.edPublic) === 'string';
|
||||||
};
|
};
|
||||||
|
|
||||||
// XXX Teams
|
|
||||||
Store.hasCurveKeys = function () {
|
Store.hasCurveKeys = function () {
|
||||||
if (!store.proxy) { return; }
|
if (!store.proxy) { return; }
|
||||||
return typeof(store.proxy.curvePrivate) === 'string' &&
|
return typeof(store.proxy.curvePrivate) === 'string' &&
|
||||||
@ -218,7 +216,6 @@ define([
|
|||||||
/////////////////////// RPC //////////////////////////////////////
|
/////////////////////// RPC //////////////////////////////////////
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// XXX Teams pin in teams
|
|
||||||
Store.pinPads = function (clientId, data, cb) {
|
Store.pinPads = function (clientId, data, cb) {
|
||||||
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
|
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
|
||||||
if (typeof(cb) !== 'function') {
|
if (typeof(cb) !== 'function') {
|
||||||
@ -231,7 +228,6 @@ define([
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// XXX Teams ...
|
|
||||||
Store.unpinPads = function (clientId, data, cb) {
|
Store.unpinPads = function (clientId, data, cb) {
|
||||||
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
|
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
|
||||||
|
|
||||||
@ -284,6 +280,7 @@ define([
|
|||||||
cb(account);
|
cb(account);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// clearOwnedChannel is only used for private chat at the moment
|
||||||
Store.clearOwnedChannel = function (clientId, data, cb) {
|
Store.clearOwnedChannel = function (clientId, data, cb) {
|
||||||
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
|
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
|
||||||
store.rpc.clearOwnedChannel(data, function (err) {
|
store.rpc.clearOwnedChannel(data, function (err) {
|
||||||
@ -292,22 +289,26 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
Store.removeOwnedChannel = function (clientId, data, cb) {
|
Store.removeOwnedChannel = function (clientId, data, cb) {
|
||||||
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
|
|
||||||
|
|
||||||
// "data" used to be a string (channelID), now it can also be an object
|
// "data" used to be a string (channelID), now it can also be an object
|
||||||
// data.force tells us we can safely remove the drive ID
|
// data.force tells us we can safely remove the drive ID
|
||||||
var channel = data;
|
var channel = data;
|
||||||
var force = false;
|
var force = false;
|
||||||
|
var teamId;
|
||||||
if (data && typeof(data) === "object") {
|
if (data && typeof(data) === "object") {
|
||||||
channel = data.channel;
|
channel = data.channel;
|
||||||
force = data.force;
|
force = data.force;
|
||||||
|
teamId = data.teamId;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (channel === storeChannel && !force) {
|
if (channel === storeChannel && !force) {
|
||||||
return void cb({error: 'User drive removal blocked!'});
|
return void cb({error: 'User drive removal blocked!'});
|
||||||
}
|
}
|
||||||
|
|
||||||
store.rpc.removeOwnedChannel(channel, function (err) {
|
var s = getStore(teamId);
|
||||||
|
if (!s) { return void cb({ error: 'ENOTFOUND' }); }
|
||||||
|
if (!s.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
|
||||||
|
|
||||||
|
s.rpc.removeOwnedChannel(channel, function (err) {
|
||||||
cb({error:err});
|
cb({error:err});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -334,40 +335,49 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
Store.uploadComplete = function (clientId, data, cb) {
|
Store.uploadComplete = function (clientId, data, cb) {
|
||||||
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
|
var s = getStore(teamId);
|
||||||
|
if (!s) { return void cb({ error: 'ENOTFOUND' }); }
|
||||||
|
if (!s.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
|
||||||
if (data.owned) {
|
if (data.owned) {
|
||||||
// Owned file
|
// Owned file
|
||||||
store.rpc.ownedUploadComplete(data.id, function (err, res) {
|
s.rpc.ownedUploadComplete(data.id, function (err, res) {
|
||||||
if (err) { return void cb({error:err}); }
|
if (err) { return void cb({error:err}); }
|
||||||
cb(res);
|
cb(res);
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Normal upload
|
// Normal upload
|
||||||
store.rpc.uploadComplete(data.id, function (err, res) {
|
s.rpc.uploadComplete(data.id, function (err, res) {
|
||||||
if (err) { return void cb({error:err}); }
|
if (err) { return void cb({error:err}); }
|
||||||
cb(res);
|
cb(res);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Store.uploadStatus = function (clientId, data, cb) {
|
Store.uploadStatus = function (clientId, data, cb) {
|
||||||
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
|
var s = getStore(teamId);
|
||||||
store.rpc.uploadStatus(data.size, function (err, res) {
|
if (!s) { return void cb({ error: 'ENOTFOUND' }); }
|
||||||
|
if (!s.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
|
||||||
|
s.rpc.uploadStatus(data.size, function (err, res) {
|
||||||
if (err) { return void cb({error:err}); }
|
if (err) { return void cb({error:err}); }
|
||||||
cb(res);
|
cb(res);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Store.uploadCancel = function (clientId, data, cb) {
|
Store.uploadCancel = function (clientId, data, cb) {
|
||||||
if (!store.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
|
var s = getStore(teamId);
|
||||||
store.rpc.uploadCancel(data.size, function (err, res) {
|
if (!s) { return void cb({ error: 'ENOTFOUND' }); }
|
||||||
|
if (!s.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
|
||||||
|
s.rpc.uploadCancel(data.size, function (err, res) {
|
||||||
if (err) { return void cb({error:err}); }
|
if (err) { return void cb({error:err}); }
|
||||||
cb(res);
|
cb(res);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Store.uploadChunk = function (clientId, data, cb) {
|
Store.uploadChunk = function (clientId, data, cb) {
|
||||||
store.rpc.send.unauthenticated('UPLOAD', data.chunk, function (e, msg) {
|
var s = getStore(teamId);
|
||||||
|
if (!s) { return void cb({ error: 'ENOTFOUND' }); }
|
||||||
|
if (!s.rpc) { return void cb({error: 'RPC_NOT_READY'}); }
|
||||||
|
s.rpc.send.unauthenticated('UPLOAD', data.chunk, function (e, msg) {
|
||||||
cb({
|
cb({
|
||||||
error: e,
|
error: e,
|
||||||
msg: msg
|
msg: msg
|
||||||
@ -393,7 +403,7 @@ define([
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Store.initRpc = function (clientId, data, cb) {
|
var initRpc = function (clientId, data, cb) {
|
||||||
if (!store.loggedIn) { return cb(); }
|
if (!store.loggedIn) { return cb(); }
|
||||||
if (store.rpc) { return void cb(account); }
|
if (store.rpc) { return void cb(account); }
|
||||||
require(['/common/pinpad.js'], function (Pinpad) {
|
require(['/common/pinpad.js'], function (Pinpad) {
|
||||||
@ -486,7 +496,7 @@ define([
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Store.initAnonRpc = function (clientId, data, cb) {
|
var initAnonRpc = function (clientId, data, cb) {
|
||||||
if (store.anon_rpc) { return void cb(); }
|
if (store.anon_rpc) { return void cb(); }
|
||||||
require([
|
require([
|
||||||
'/common/rpc.js',
|
'/common/rpc.js',
|
||||||
@ -580,12 +590,17 @@ define([
|
|||||||
if (data.expire) { pad.expire = data.expire; }
|
if (data.expire) { pad.expire = data.expire; }
|
||||||
if (data.password) { pad.password = data.password; }
|
if (data.password) { pad.password = data.password; }
|
||||||
if (data.channel || secret) { pad.channel = data.channel || secret.channel; }
|
if (data.channel || secret) { pad.channel = data.channel || secret.channel; }
|
||||||
store.manager.addPad(data.path, pad, function (e) {
|
|
||||||
|
var s = getStore(data.teamId);
|
||||||
|
if (!s || !s.manager) { return void cb({ error: 'ENOTFOUND' }); }
|
||||||
|
|
||||||
|
s.manager.addPad(data.path, pad, function (e) {
|
||||||
if (e) { return void cb({error: e}); }
|
if (e) { return void cb({error: e}); }
|
||||||
sendDriveEvent('DRIVE_CHANGE', {
|
var send = data.teamId ? s.sendEvent : sendDriveEvent;
|
||||||
|
send('DRIVE_CHANGE', {
|
||||||
path: ['drive', UserObject.FILES_DATA]
|
path: ['drive', UserObject.FILES_DATA]
|
||||||
}, clientId);
|
}, clientId);
|
||||||
onSync(cb);
|
onSync(teamId, cb);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1849,7 +1864,7 @@ define([
|
|||||||
settings: proxy.settings
|
settings: proxy.settings
|
||||||
}, {
|
}, {
|
||||||
outer: true,
|
outer: true,
|
||||||
removeOwnedChannel: function (data, cb) { Store.removeOwnedChannel('', data, cb); },
|
removeOwnedChannel: function (channel, cb) { Store.removeOwnedChannel('', channel, cb); },
|
||||||
edPublic: store.proxy.edPublic,
|
edPublic: store.proxy.edPublic,
|
||||||
loggedIn: store.loggedIn,
|
loggedIn: store.loggedIn,
|
||||||
log: function (msg) {
|
log: function (msg) {
|
||||||
@ -1866,8 +1881,8 @@ define([
|
|||||||
});
|
});
|
||||||
userObject.migrate(waitFor());
|
userObject.migrate(waitFor());
|
||||||
}).nThen(function (waitFor) {
|
}).nThen(function (waitFor) {
|
||||||
Store.initAnonRpc(null, null, waitFor());
|
initAnonRpc(null, null, waitFor());
|
||||||
Store.initRpc(null, null, waitFor());
|
initRpc(null, null, waitFor());
|
||||||
}).nThen(function (waitFor) {
|
}).nThen(function (waitFor) {
|
||||||
loadMailbox(waitFor);
|
loadMailbox(waitFor);
|
||||||
Migrate(proxy, waitFor(), function (version, progress) {
|
Migrate(proxy, waitFor(), function (version, progress) {
|
||||||
|
|||||||
@ -14,7 +14,6 @@ define([
|
|||||||
CREATE_README: Store.createReadme,
|
CREATE_README: Store.createReadme,
|
||||||
MIGRATE_ANON_DRIVE: Store.migrateAnonDrive,
|
MIGRATE_ANON_DRIVE: Store.migrateAnonDrive,
|
||||||
// RPC
|
// RPC
|
||||||
INIT_RPC: Store.initRpc,
|
|
||||||
UPDATE_PIN_LIMIT: Store.updatePinLimit,
|
UPDATE_PIN_LIMIT: Store.updatePinLimit,
|
||||||
GET_PIN_LIMIT: Store.getPinLimit,
|
GET_PIN_LIMIT: Store.getPinLimit,
|
||||||
CLEAR_OWNED_CHANNEL: Store.clearOwnedChannel,
|
CLEAR_OWNED_CHANNEL: Store.clearOwnedChannel,
|
||||||
@ -30,7 +29,6 @@ define([
|
|||||||
GET_DELETED_PADS: Store.getDeletedPads,
|
GET_DELETED_PADS: Store.getDeletedPads,
|
||||||
GET_PINNED_USAGE: Store.getPinnedUsage,
|
GET_PINNED_USAGE: Store.getPinnedUsage,
|
||||||
// ANON RPC
|
// ANON RPC
|
||||||
INIT_ANON_RPC: Store.initAnonRpc,
|
|
||||||
ANON_RPC_MESSAGE: Store.anonRpcMsg,
|
ANON_RPC_MESSAGE: Store.anonRpcMsg,
|
||||||
GET_FILE_SIZE: Store.getFileSize,
|
GET_FILE_SIZE: Store.getFileSize,
|
||||||
GET_MULTIPLE_FILE_SIZE: Store.getMultipleFileSize,
|
GET_MULTIPLE_FILE_SIZE: Store.getMultipleFileSize,
|
||||||
|
|||||||
@ -28,11 +28,15 @@ define([
|
|||||||
// TODO: pin or unpin document added to a shared folder from someone who is not a member of the team
|
// TODO: pin or unpin document added to a shared folder from someone who is not a member of the team
|
||||||
};
|
};
|
||||||
|
|
||||||
var onready = function (ctx, team, id, cb) {
|
var onReady = function (ctx, team, id, cb) {
|
||||||
// XXX
|
// XXX
|
||||||
|
// sanity check: do we have all the required keys?
|
||||||
|
// initialize team rpc with pin, unpin, ...
|
||||||
|
// team.rpc = rpc
|
||||||
// load manager
|
// load manager
|
||||||
// load shared folders
|
// load shared folders
|
||||||
|
// ~resetPins for the team?
|
||||||
|
// getPinLimit
|
||||||
};
|
};
|
||||||
|
|
||||||
var openChannel = function (ctx, team, id, cb) {
|
var openChannel = function (ctx, team, id, cb) {
|
||||||
@ -55,6 +59,12 @@ define([
|
|||||||
var lm = Listmap.create(cfg);
|
var lm = Listmap.create(cfg);
|
||||||
lm.proxy.on('create', function () {
|
lm.proxy.on('create', function () {
|
||||||
}).on('ready', function () {
|
}).on('ready', function () {
|
||||||
|
var sendEvent = function (type, data, sender) {
|
||||||
|
// XXX emit UPDATE event to the inner iframe
|
||||||
|
// don't send the event back to the sender
|
||||||
|
// types are DRIVE_CHANGE, DRIVE_REMOVE and DRIVE_LOG
|
||||||
|
};
|
||||||
|
|
||||||
ctx.teams[id] = {
|
ctx.teams[id] = {
|
||||||
proxy: lm.proxy,
|
proxy: lm.proxy,
|
||||||
listmap: lm,
|
listmap: lm,
|
||||||
@ -62,7 +72,8 @@ define([
|
|||||||
manager: undefined, // XXX
|
manager: undefined, // XXX
|
||||||
realtime: lm.realtime,
|
realtime: lm.realtime,
|
||||||
handleSharedFolder: function (sfId, rt) { handleSharedFolder(ctx, id, sfId, rt); },
|
handleSharedFolder: function (sfId, rt) { handleSharedFolder(ctx, id, sfId, rt); },
|
||||||
sharedFolders: {} // equivalent of store.sharedFolders in async-store
|
sharedFolders: {}, // equivalent of store.sharedFolders in async-store
|
||||||
|
sendEvent: sendEvent
|
||||||
};
|
};
|
||||||
|
|
||||||
onReady(ctx, team, id, function () {
|
onReady(ctx, team, id, function () {
|
||||||
|
|||||||
@ -12,6 +12,7 @@ define([
|
|||||||
var metadata = file.metadata;
|
var metadata = file.metadata;
|
||||||
|
|
||||||
var owned = file.owned;
|
var owned = file.owned;
|
||||||
|
var teamId = file.teamId;
|
||||||
|
|
||||||
// if it exists, path contains the new pad location in the drive
|
// if it exists, path contains the new pad location in the drive
|
||||||
var path = file.path;
|
var path = file.path;
|
||||||
@ -43,8 +44,9 @@ define([
|
|||||||
getValidHash(waitFor());
|
getValidHash(waitFor());
|
||||||
}).nThen(function (waitFor) {
|
}).nThen(function (waitFor) {
|
||||||
if (!owned) { return; }
|
if (!owned) { return; }
|
||||||
common.getMetadata(waitFor(function (err, m) {
|
common.getEdPublic(teamId, waitFor(function (obj) {
|
||||||
edPublic = m.priv.edPublic;
|
if (obj && obj.error) { return; }
|
||||||
|
edPublic = obj;
|
||||||
metadata.owners = [edPublic];
|
metadata.owners = [edPublic];
|
||||||
}));
|
}));
|
||||||
}).nThen(function () {
|
}).nThen(function () {
|
||||||
@ -54,7 +56,7 @@ define([
|
|||||||
|
|
||||||
var sendChunk = function (box, cb) {
|
var sendChunk = function (box, cb) {
|
||||||
var enc = Nacl.util.encodeBase64(box);
|
var enc = Nacl.util.encodeBase64(box);
|
||||||
common.uploadChunk(enc, function (e, msg) {
|
common.uploadChunk(teamId, enc, function (e, msg) {
|
||||||
cb(e, msg);
|
cb(e, msg);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -79,7 +81,7 @@ define([
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if not box then done
|
// if not box then done
|
||||||
common.uploadComplete(id, owned, function (e) {
|
common.uploadComplete(teamId, id, owned, function (e) {
|
||||||
if (e) { return void console.error(e); }
|
if (e) { return void console.error(e); }
|
||||||
var uri = ['', 'blob', id.slice(0,2), id].join('/');
|
var uri = ['', 'blob', id.slice(0,2), id].join('/');
|
||||||
console.log("encrypted blob is now available as %s", uri);
|
console.log("encrypted blob is now available as %s", uri);
|
||||||
@ -90,6 +92,7 @@ define([
|
|||||||
if (noStore) { return void onComplete(href); }
|
if (noStore) { return void onComplete(href); }
|
||||||
|
|
||||||
var data = {
|
var data = {
|
||||||
|
teamId: teamId,
|
||||||
title: title || "",
|
title: title || "",
|
||||||
href: href,
|
href: href,
|
||||||
path: path,
|
path: path,
|
||||||
@ -107,7 +110,7 @@ define([
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
common.uploadStatus(estimate, function (e, pending) {
|
common.uploadStatus(teamId, estimate, function (e, pending) {
|
||||||
if (e) {
|
if (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
onError(e);
|
onError(e);
|
||||||
@ -117,7 +120,7 @@ define([
|
|||||||
if (pending) {
|
if (pending) {
|
||||||
return void onPending(function () {
|
return void onPending(function () {
|
||||||
// if the user wants to cancel the pending upload to execute that one
|
// if the user wants to cancel the pending upload to execute that one
|
||||||
common.uploadCancel(estimate, function (e) {
|
common.uploadCancel(teamId, estimate, function (e) {
|
||||||
if (e) {
|
if (e) {
|
||||||
return void console.error(e);
|
return void console.error(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,6 +33,8 @@ define([
|
|||||||
var File = {};
|
var File = {};
|
||||||
var origin = common.getMetadataMgr().getPrivateData().origin;
|
var origin = common.getMetadataMgr().getPrivateData().origin;
|
||||||
|
|
||||||
|
var teamId = config.teamId; // XXX Teams file upload as a team
|
||||||
|
|
||||||
var queue = File.queue = {
|
var queue = File.queue = {
|
||||||
queue: [],
|
queue: [],
|
||||||
inProgress: false
|
inProgress: false
|
||||||
@ -165,6 +167,7 @@ define([
|
|||||||
file.noStore = config.noStore;
|
file.noStore = config.noStore;
|
||||||
try {
|
try {
|
||||||
file.blob = Nacl.util.encodeBase64(u8);
|
file.blob = Nacl.util.encodeBase64(u8);
|
||||||
|
file.teamId = teamId;
|
||||||
common.uploadFile(file, function () {
|
common.uploadFile(file, function () {
|
||||||
console.log('Upload started...');
|
console.log('Upload started...');
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user