From 5749b6fd7b5509ff979154ae7366967ba37d3691 Mon Sep 17 00:00:00 2001 From: ansuz Date: Fri, 25 Sep 2020 14:24:26 +0530 Subject: [PATCH] add an admin RPC to archive documents --- lib/commands/admin-rpc.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/lib/commands/admin-rpc.js b/lib/commands/admin-rpc.js index c60cdcfbc..df21da3e6 100644 --- a/lib/commands/admin-rpc.js +++ b/lib/commands/admin-rpc.js @@ -146,6 +146,32 @@ var flushCache = function (Env, Server, cb) { cb(void 0, true); }; +// CryptPad_AsyncStore.rpc.send('ADMIN', ['ARCHIVE_DOCUMENT', documentID], console.log) +var archiveDocument = function (Env, Server, cb, data) { + var id = Array.isArray(data) && data[1]; + if (typeof(id) !== 'string' || id.length < 32) { return void cb("EINVAL"); } + + switch (id.length) { + case 32: + return void Env.msgStore.archiveChannel(id, cb); + case 48: + return void Env.blobStore.archive.blob(id, cb); + default: + return void cb("INVALID_ID_LENGTH"); + } + + // archival for blob proofs isn't automated, but evict-inactive.js will + // clean up orpaned blob proofs + // Env.blobStore.archive.proof(userSafeKey, blobId, cb) +}; + +var restoreArchivedDocument = function (Env, Server, cb) { + // Env.msgStore.restoreArchivedChannel(channelName, cb) + // Env.blobStore.restore.blob(blobId, cb) + // Env.blobStore.restore.proof(userSafekey, blobId, cb) + + cb("NOT_IMPLEMENTED"); +}; // CryptPad_AsyncStore.rpc.send('ADMIN', ['SET_DEFAULT_STORAGE_LIMIT', 1024 * 1024 * 1024 /* 1GB */], console.log) var setDefaultStorageLimit = function (Env, Server, cb, data) { @@ -174,6 +200,9 @@ var commands = { GET_FILE_DESCRIPTOR_LIMIT: getFileDescriptorLimit, SET_DEFAULT_STORAGE_LIMIT: setDefaultStorageLimit, GET_CACHE_STATS: getCacheStats, + + ARCHIVE_DOCUMENT: archiveDocument, + RESTORE_ARCHIVED_DOCUMENT: restoreArchivedDocument, }; Admin.command = function (Env, safeKey, data, _cb, Server) {