new getDeletedPads rpc

This commit is contained in:
ansuz
2018-01-29 12:40:09 +01:00
parent 5089f1206d
commit f134f11b73
3 changed files with 73 additions and 14 deletions

40
rpc.js
View File

@@ -11,6 +11,8 @@ var Path = require("path");
var Https = require("https");
const Package = require('./package.json');
const Pinned = require('./pinned');
const Saferphore = require("saferphore");
const nThen = require("nthen");
var RPC = module.exports;
@@ -355,6 +357,33 @@ var getMultipleFileSize = function (Env, channels, cb) {
});
};
/* accepts a list, and returns a sublist of channel or file ids which seem
to have been deleted from the server (file size 0)
we might consider that we should only say a file is gone if fs.stat returns
ENOENT, but for now it's simplest to just rely on getFileSize...
*/
var getDeletedPads = function (Env, channels, cb) {
if (!Array.isArray(channels)) { return cb('INVALID_LIST'); }
var L = channels.length;
var sem = Saferphore.create(10);
var absentees = [];
nThen(function (w) {
for (var i = 0; i < L; i++) {
let channel = channels[i];
sem.take(function (give) {
getFileSize(Env, channel, w(give(function (e, size) {
if (e) { return; }
if (size === 0) { absentees.push(channel); }
})));
});
}
}).nThen(function () {
cb(void 0, absentees);
});
};
var getTotalSize = function (Env, publicKey, cb) {
var bytes = 0;
return void getChannelList(Env, publicKey, function (channels) {
@@ -1005,7 +1034,8 @@ var isUnauthenticatedCall = function (call) {
'GET_MULTIPLE_FILE_SIZE',
'IS_CHANNEL_PINNED',
'IS_NEW_CHANNEL',
'GET_HISTORY_OFFSET'
'GET_HISTORY_OFFSET',
'GET_DELETED_PADS',
].indexOf(call) !== -1;
};
@@ -1128,6 +1158,14 @@ RPC.create = function (config /*:Config_t*/, cb /*:(?Error, ?Function)=>void*/)
}
respond(e, [null, dict, null]);
});
case 'GET_DELETED_PADS':
return void getDeletedPads(Env, msg[1], function (e, list) {
if (e) {
WARN(e, msg[1]);
return respond(e);
}
respond(e, [null, list, null]);
});
case 'IS_CHANNEL_PINNED':
return void isChannelPinned(Env, msg[1], function (isPinned) {
respond(null, [null, isPinned, null]);