|
|
@ -52,6 +52,12 @@ define([
|
|
|
|
return channels;
|
|
|
|
return channels;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var getEdPublic = function (ctx, teamId) {
|
|
|
|
|
|
|
|
if (!teamId) { return Util.find(ctx.store, ['proxy', 'edPublic']); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var teamData = Util.find(ctx, ['store', 'proxy', 'teams', teamId]);
|
|
|
|
|
|
|
|
return Util.find(teamData, ['keys', 'drive', 'edPublic']);
|
|
|
|
|
|
|
|
};
|
|
|
|
var getRpc = function (ctx, teamId) {
|
|
|
|
var getRpc = function (ctx, teamId) {
|
|
|
|
if (!teamId) { return ctx.store.rpc; }
|
|
|
|
if (!teamId) { return ctx.store.rpc; }
|
|
|
|
var teams = ctx.store.modules['team'];
|
|
|
|
var teams = ctx.store.modules['team'];
|
|
|
@ -61,14 +67,77 @@ define([
|
|
|
|
return team.rpc;
|
|
|
|
return team.rpc;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var getHistoryData = function (ctx, channel, lastKnownHash, teamId, _cb) {
|
|
|
|
|
|
|
|
var cb = Util.once(Util.mkAsync(_cb));
|
|
|
|
|
|
|
|
var edPublic = getEdPublic(ctx, teamId);
|
|
|
|
|
|
|
|
var Store = ctx.Store;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var total = 0;
|
|
|
|
|
|
|
|
var history = 0;
|
|
|
|
|
|
|
|
var metadata = 0;
|
|
|
|
|
|
|
|
var hash;
|
|
|
|
|
|
|
|
nThen(function (waitFor) {
|
|
|
|
|
|
|
|
// Total size
|
|
|
|
|
|
|
|
Store.getFileSize(null, {
|
|
|
|
|
|
|
|
channel: channel
|
|
|
|
|
|
|
|
}, waitFor(function (obj) {
|
|
|
|
|
|
|
|
if (obj && obj.error) {
|
|
|
|
|
|
|
|
waitFor.abort();
|
|
|
|
|
|
|
|
return void cb(obj);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof(obj.size) === "undefined") {
|
|
|
|
|
|
|
|
waitFor.abort();
|
|
|
|
|
|
|
|
return void cb({error: 'ENOENT'});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
total = obj.size;
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
// Pad
|
|
|
|
|
|
|
|
Store.getHistory(null, {
|
|
|
|
|
|
|
|
channel: channel,
|
|
|
|
|
|
|
|
lastKnownHash: lastKnownHash
|
|
|
|
|
|
|
|
}, waitFor(function (obj) {
|
|
|
|
|
|
|
|
if (obj && obj.error) {
|
|
|
|
|
|
|
|
waitFor.abort();
|
|
|
|
|
|
|
|
return void cb(obj);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Array.isArray(obj)) {
|
|
|
|
|
|
|
|
waitFor.abort();
|
|
|
|
|
|
|
|
return void cb({error: 'EINVAL'});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hash = obj[0].hash;
|
|
|
|
|
|
|
|
var messages = obj.map(function(data) {
|
|
|
|
|
|
|
|
return data.msg;
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
history = messages.join('\n').length;
|
|
|
|
|
|
|
|
}), true);
|
|
|
|
|
|
|
|
// Metadata
|
|
|
|
|
|
|
|
Store.getPadMetadata(null, {
|
|
|
|
|
|
|
|
channel: channel
|
|
|
|
|
|
|
|
}, waitFor(function (obj) {
|
|
|
|
|
|
|
|
if (obj && obj.error) { return; }
|
|
|
|
|
|
|
|
if (!obj || typeof(obj) !== "object") { return; }
|
|
|
|
|
|
|
|
metadata = JSON.stringify(obj).length;
|
|
|
|
|
|
|
|
if (!obj || !Array.isArray(obj.owners) ||
|
|
|
|
|
|
|
|
obj.owners.indexOf(edPublic) === -1) {
|
|
|
|
|
|
|
|
waitFor.abort();
|
|
|
|
|
|
|
|
return void cb({error: 'INSUFFICIENT_PERMISSIONS'});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
}).nThen(function () {
|
|
|
|
|
|
|
|
cb({
|
|
|
|
|
|
|
|
size: (total - metadata - history),
|
|
|
|
|
|
|
|
hash: hash
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
commands.GET_HISTORY_SIZE = function (ctx, data, cId, cb) {
|
|
|
|
commands.GET_HISTORY_SIZE = function (ctx, data, cId, cb) {
|
|
|
|
if (!ctx.store.loggedIn || !ctx.store.rpc) { return void cb({ error: 'INSUFFICIENT_PERMISSIONS' }); }
|
|
|
|
if (!ctx.store.loggedIn || !ctx.store.rpc) { return void cb({ error: 'INSUFFICIENT_PERMISSIONS' }); }
|
|
|
|
var channels = data.channels;
|
|
|
|
var channels = data.channels;
|
|
|
|
if (!Array.isArray(channels)) { return void cb({ error: 'EINVAL' }); }
|
|
|
|
if (!Array.isArray(channels)) { return void cb({ error: 'EINVAL' }); }
|
|
|
|
|
|
|
|
|
|
|
|
var rpc = getRpc(ctx, data.teamid);
|
|
|
|
|
|
|
|
if (!rpc) { return void cb({ error: 'ENORPC'}); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var warning = [];
|
|
|
|
var warning = [];
|
|
|
|
|
|
|
|
|
|
|
|
// If account trim history, get the correct channels here
|
|
|
|
// If account trim history, get the correct channels here
|
|
|
@ -77,30 +146,26 @@ define([
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var size = 0;
|
|
|
|
var size = 0;
|
|
|
|
|
|
|
|
var res = [];
|
|
|
|
nThen(function (waitFor) {
|
|
|
|
nThen(function (waitFor) {
|
|
|
|
// TODO: check if owner first?
|
|
|
|
|
|
|
|
channels.forEach(function (chan) {
|
|
|
|
channels.forEach(function (chan) {
|
|
|
|
size += Math.floor(Math.random()*1000) * 1024; // XXX
|
|
|
|
|
|
|
|
chan = chan; // XXX
|
|
|
|
|
|
|
|
waitFor = waitFor; // XXX
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
var channel = chan;
|
|
|
|
var channel = chan;
|
|
|
|
var lastKnownHash;
|
|
|
|
var lastKnownHash;
|
|
|
|
if (typeof (chan) === "object" && chan.channel) {
|
|
|
|
if (typeof (chan) === "object" && chan.channel) {
|
|
|
|
channel = chan.channel;
|
|
|
|
channel = chan.channel;
|
|
|
|
lastKnownHash = chan.lastKnownHash;
|
|
|
|
lastKnownHash = chan.lastKnownHash;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rpc.getHistorySize({
|
|
|
|
getHistoryData(ctx, channel, lastKnownHash, data.teamId, waitFor(function (obj) {
|
|
|
|
channel: channel,
|
|
|
|
if (obj && obj.error) {
|
|
|
|
lastKnownHash: lastKnownHash
|
|
|
|
warning.push(obj.error);
|
|
|
|
}, waitFor(function (err, value) {
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
|
|
|
|
warning.push(err);
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
size += value;
|
|
|
|
size += obj.size;
|
|
|
|
|
|
|
|
res.push({
|
|
|
|
|
|
|
|
channel: channel,
|
|
|
|
|
|
|
|
lastKnownHash: obj.hash
|
|
|
|
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
*/ // XXX TODO
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}).nThen(function () {
|
|
|
|
}).nThen(function () {
|
|
|
|
cb({
|
|
|
|
cb({
|
|
|
@ -115,7 +180,7 @@ define([
|
|
|
|
var channels = data.channels;
|
|
|
|
var channels = data.channels;
|
|
|
|
if (!Array.isArray(channels)) { return void cb({ error: 'EINVAL' }); }
|
|
|
|
if (!Array.isArray(channels)) { return void cb({ error: 'EINVAL' }); }
|
|
|
|
|
|
|
|
|
|
|
|
var rpc = getRpc(ctx, data.teamid);
|
|
|
|
var rpc = getRpc(ctx, data.teamId);
|
|
|
|
if (!rpc) { return void cb({ error: 'ENORPC'}); }
|
|
|
|
if (!rpc) { return void cb({ error: 'ENORPC'}); }
|
|
|
|
|
|
|
|
|
|
|
|
var warning = [];
|
|
|
|
var warning = [];
|
|
|
|