From 488ec93ecebb02d78f22c004f3b3f73d46afdd33 Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 20 Oct 2020 17:07:55 +0530 Subject: [PATCH] allow expert admins to get and clear cached channel indices --- lib/commands/admin-rpc.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/commands/admin-rpc.js b/lib/commands/admin-rpc.js index e67f75f6c..b7c5dfa52 100644 --- a/lib/commands/admin-rpc.js +++ b/lib/commands/admin-rpc.js @@ -175,6 +175,24 @@ var restoreArchivedDocument = function (Env, Server, cb) { cb("NOT_IMPLEMENTED"); }; +// CryptPad_AsyncStore.rpc.send('ADMIN', ['CLEAR_CHANNEL_INDEX', documentID], console.log) +var clearChannelIndex = function (Env, Server, cb, data) { + var id = Array.isArray(data) && data[1]; + if (typeof(id) !== 'string' || id.length < 32) { return void cb("EINVAL"); } + delete Env.channel_cache[id]; + cb(); +}; + +// CryptPad_AsyncStore.rpc.send('ADMIN', ['GET_CHANNEL_INDEX', documentID], console.log) +var getChannelIndex = function (Env, Server, cb, data) { + var id = Array.isArray(data) && data[1]; + if (typeof(id) !== 'string' || id.length < 32) { return void cb("EINVAL"); } + + var index = Util.find(Env, ['channel_cache', id]); + if (!index) { return void cb("ENOENT"); } + cb(void 0, index); +}; + // CryptPad_AsyncStore.rpc.send('ADMIN', [ 'ADMIN_DECREE', ['RESTRICT_REGISTRATION', [true]]], console.log) var adminDecree = function (Env, Server, cb, data, unsafeKey) { var value = data[1]; @@ -269,6 +287,9 @@ var commands = { ARCHIVE_DOCUMENT: archiveDocument, RESTORE_ARCHIVED_DOCUMENT: restoreArchivedDocument, + CLEAR_CHANNEL_INDEX: clearChannelIndex, + GET_CHANNEL_INDEX: getChannelIndex, + ADMIN_DECREE: adminDecree, INSTANCE_STATUS: instanceStatus, GET_LIMITS: getLimits,