From 210fac321b222420a26b6b37a320c02560e89094 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 8 Dec 2024 14:05:14 +0200 Subject: [PATCH] Move config reading to top-level --- src/endpoints/chats.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/endpoints/chats.js b/src/endpoints/chats.js index 70817e037..1e7a00d08 100644 --- a/src/endpoints/chats.js +++ b/src/endpoints/chats.js @@ -11,6 +11,10 @@ import _ from 'lodash'; import { jsonParser, urlencodedParser } from '../express-common.js'; import { getConfigValue, humanizedISO8601DateTime, tryParse, generateTimestamp, removeOldBackups } from '../util.js'; +const isBackupDisabled = getConfigValue('disableChatBackup', false); +const maxTotalChatBackups = Number(getConfigValue('maxTotalChatBackups', -1)); +const throttleInterval = getConfigValue('chatBackupThrottleInterval', 10_000); + /** * Saves a chat to the backups directory. * @param {string} directory The user's backups directory. @@ -19,7 +23,6 @@ import { getConfigValue, humanizedISO8601DateTime, tryParse, generateTimestamp, */ function backupChat(directory, name, chat) { try { - const isBackupDisabled = getConfigValue('disableChatBackup', false); if (isBackupDisabled) { return; @@ -33,7 +36,6 @@ function backupChat(directory, name, chat) { removeOldBackups(directory, `chat_${name}_`); - const maxTotalChatBackups = Number(getConfigValue('maxTotalChatBackups', -1)); if (isNaN(maxTotalChatBackups) || maxTotalChatBackups < 0) { return; } @@ -52,7 +54,6 @@ const backupFunctions = new Map(); * @returns {function(string, string, string): void} Backup function */ function getBackupFunction(handle) { - const throttleInterval = getConfigValue('chatBackupThrottleInterval', 10_000); if (!backupFunctions.has(handle)) { backupFunctions.set(handle, _.throttle(backupChat, throttleInterval, { leading: true, trailing: true })); }