From b135e815e7bd353ac7240ecffbdfb904c5cf7711 Mon Sep 17 00:00:00 2001 From: yflory Date: Tue, 14 Jan 2025 18:13:45 +0100 Subject: [PATCH 1/7] Allow new types of decrees in different files --- lib/commands/admin-rpc.js | 13 ++ lib/decrees-core.js | 141 +++++++++++++++++ lib/decrees.js | 324 ++++++++++++-------------------------- lib/env.js | 2 +- lib/http-worker.js | 15 +- lib/load-config.js | 7 - package-lock.json | 16 +- package.json | 2 +- www/admin/inner.js | 22 ++- 9 files changed, 287 insertions(+), 255 deletions(-) create mode 100644 lib/decrees-core.js diff --git a/lib/commands/admin-rpc.js b/lib/commands/admin-rpc.js index 9030159f8..b682bbf62 100644 --- a/lib/commands/admin-rpc.js +++ b/lib/commands/admin-rpc.js @@ -1138,6 +1138,19 @@ Admin.command = function (Env, safeKey, data, _cb, Server) { var command = commands[data[0]]; + Object.keys(Env.plugins || {}).forEach(name => { + let plugin = Env.plugins[name]; + if (!plugin.addAdminCommands) { return; } + try { + let c = plugin.addAdminCommands(Env); + Object.keys(c || {}).forEach(cmd => { + if (typeof(c[cmd]) !== "function") { return; } + if (commands[cmd]) { return; } + commands[cmd] = c[cmd]; + }); + } catch (e) {} + }); + if (typeof(command) === 'function') { return void command(Env, Server, cb, data, unsafeKey); } diff --git a/lib/decrees-core.js b/lib/decrees-core.js new file mode 100644 index 000000000..a8320a922 --- /dev/null +++ b/lib/decrees-core.js @@ -0,0 +1,141 @@ +// SPDX-FileCopyrightText: 2023 XWiki CryptPad Team and contributors +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +var Decrees = module.exports; +var Util = require("./common-util"); +var Fs = require("fs"); +var Path = require("path"); +var readFileBin = require("./stream-file").readFileBin; +var Schedule = require("./schedule"); +var Fse = require("fs-extra"); +var nThen = require("nthen"); + + +const Utils = Decrees.Utils = {}; +var isString = (str) => { + return typeof(str) === "string"; +}; +var isInteger = function (n) { + return !(typeof(n) !== 'number' || isNaN(n) || (n % 1) !== 0); +}; +Utils.args_isBoolean = function (args) { + return !(!Array.isArray(args) || typeof(args[0]) !== 'boolean'); +}; +Utils.args_isString = function (args) { + return !(!Array.isArray(args) || !isString(args[0])); +}; +Utils.args_isInteger = function (args) { + return !(!Array.isArray(args) || !isInteger(args[0])); +}; +Utils.args_isPositiveInteger = function (args) { + return Array.isArray(args) && isInteger(args[0]) && args[0] > 0; +}; + + +Decrees.create = (name, commands) => { + // [, , ,