Merge branch 'staging' of github.com:xwiki-labs/cryptpad into staging

pull/1/head
yflory 8 years ago
commit b9c64a526a

@ -230,7 +230,7 @@ const handleMessage = function (ctx, user, msg) {
var rpc_call = parsed.slice(1);
// slice off the sequence number and pass in the rest of the message
ctx.rpc(rpc_call, function (err, output) {
ctx.rpc(ctx, rpc_call, function (err, output) {
if (err) {
console.error('[' + err + ']', output); // TODO make this disableable
sendMsg(ctx, user, [seq, 'ACK']);

@ -11,11 +11,15 @@ var getHash = function (ctx, cb) { };
var getTotalSize = function (ctx, cb) { };
var getFileSize = function (ctx, cb) { };
var isValidChannel = function (chan) {
return /^[a-fA-F0-9]/.test(chan);
};
RPC.create = function (config, cb) {
// load pin-store...
console.log('loading rpc module...');
rpc = function (msg, respond) {
var rpc = function (ctx, msg, respond) {
switch (msg[0]) {
case 'ECHO':
respond(void 0, msg);
@ -25,7 +29,14 @@ RPC.create = function (config, cb) {
case 'GET_HASH':
case 'GET_TOTAL_SIZE':
case 'GET_FILE_SIZE':
if (!isValidChannel(msg[1])) {
return void respond('INVALID_CHAN');
}
return void ctx.store.getChannelSize(msg[1], function (e, size) {
if (e) { return void respond(e.code); }
respond(void 0, size);
});
default:
respond('UNSUPPORTED_RPC_CALL', msg);
break;

@ -216,6 +216,14 @@ var getMessages = function (env, chanName, handler, cb) {
});
};
var channelBytes = function (env, chanName, cb) {
var path = mkPath(env, chanName);
Fs.stat(path, function (err, stats) {
if (err) { return void cb(err); }
cb(void 0, stats.size);
});
};
module.exports.create = function (conf, cb) {
var env = {
root: conf.filePath || './datastore',
@ -248,6 +256,9 @@ module.exports.create = function (conf, cb) {
flushUnusedChannels: function (cb) {
flushUnusedChannels(env, cb);
},
getChannelSize: function (chanName, cb) {
channelBytes(env, chanName, cb);
},
});
});
setInterval(function () {

@ -987,6 +987,28 @@ define([
});
*/
};
var getUserChannelList = common.getUserChannelList = function () {
var store = common.getStore();
var proxy = store.getProxy();
var fo = proxy.fo;
var list = fo.getFilesDataFiles().map(function (href) {
var parsed = common.parsePadUrl(href);
if (!parsed || !parsed.hash) { return; }
parsed = common.parseHash(parsed.hash);
var channel = parsed.channel;
if (!channel) { return; }
var hex = common.base64ToHex(channel);
return hex;
}).filter(function (x) { return x; }).sort();
return list;
};
var createButton = common.createButton = function (type, rightside, data, callback) {
var button;
var size = "17px";

@ -30,6 +30,20 @@ define([
if (e) { return void console.error(e); }
console.log(msg);
});
var list = Cryptpad.getUserChannelList();
if (list.length) {
rpc.send('GET_FILE_SIZE', list[0], function (e, msg) {
if (e) {
return void console.error(e);
}
console.log(msg);
});
}
rpc.send('GET_FILE_SIZE', 'pewpew', function (e, msg) {
if (e) { return void console.error(e); }
console.log(msg);
});
});
});
});

Loading…
Cancel
Save