manual merge
This commit is contained in:
44
rpc.js
44
rpc.js
@@ -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,37 @@ 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 = [];
|
||||
|
||||
var job = function (channel, wait) {
|
||||
return function (give) {
|
||||
getFileSize(Env, channel, wait(give(function (e, size) {
|
||||
if (e) { return; }
|
||||
if (size === 0) { absentees.push(channel); }
|
||||
})));
|
||||
};
|
||||
};
|
||||
|
||||
nThen(function (w) {
|
||||
for (var i = 0; i < L; i++) {
|
||||
sem.take(job(channels[i], w));
|
||||
}
|
||||
}).nThen(function () {
|
||||
cb(void 0, absentees);
|
||||
});
|
||||
};
|
||||
|
||||
var getTotalSize = function (Env, publicKey, cb) {
|
||||
var bytes = 0;
|
||||
return void getChannelList(Env, publicKey, function (channels) {
|
||||
@@ -1004,7 +1037,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;
|
||||
};
|
||||
|
||||
@@ -1133,6 +1167,14 @@ RPC.create = function (
|
||||
}
|
||||
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]);
|
||||
|
||||
Reference in New Issue
Block a user