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 })); }