respond to GET_FILE_SIZE rpc calls

This commit is contained in:
ansuz
2017-03-15 15:55:25 +01:00
parent d0466a2052
commit 61fc4a3f86
2 changed files with 13 additions and 2 deletions

13
rpc.js
View File

@@ -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) {
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;