Move config reading to top-level
| @@ -11,6 +11,10 @@ import _ from 'lodash'; | ||
| 11 | 11 | import { jsonParser, urlencodedParser } from '../express-common.js'; |
| 12 | 12 | import { getConfigValue, humanizedISO8601DateTime, tryParse, generateTimestamp, removeOldBackups } from '../util.js'; |
| 13 | 13 | |
| 14 | +const isBackupDisabled = getConfigValue('disableChatBackup', false); | |
| 15 | +const maxTotalChatBackups = Number(getConfigValue('maxTotalChatBackups', -1)); | |
| 16 | +const throttleInterval = getConfigValue('chatBackupThrottleInterval', 10_000); | |
| 17 | + | |
| 14 | 18 | /** |
| 15 | 19 | * Saves a chat to the backups directory. |
| 16 | 20 | * @param {string} directory The user's backups directory. |
| @@ -19,7 +23,6 @@ import { getConfigValue, humanizedISO8601DateTime, tryParse, generateTimestamp, | ||
| 19 | 23 | */ |
| 20 | 24 | function backupChat(directory, name, chat) { |
| 21 | 25 | try { |
| 22 | - const isBackupDisabled = getConfigValue('disableChatBackup', false); | |
| 23 | 26 | |
| 24 | 27 | if (isBackupDisabled) { |
| 25 | 28 | return; |
| @@ -33,7 +36,6 @@ function backupChat(directory, name, chat) { | ||
| 33 | 36 | |
| 34 | 37 | removeOldBackups(directory, `chat_${name}_`); |
| 35 | 38 | |
| 36 | - const maxTotalChatBackups = Number(getConfigValue('maxTotalChatBackups', -1)); | |
| 37 | 39 | if (isNaN(maxTotalChatBackups) || maxTotalChatBackups < 0) { |
| 38 | 40 | return; |
| 39 | 41 | } |
| @@ -52,7 +54,6 @@ const backupFunctions = new Map(); | ||
| 52 | 54 | * @returns {function(string, string, string): void} Backup function |
| 53 | 55 | */ |
| 54 | 56 | function getBackupFunction(handle) { |
| 55 | - const throttleInterval = getConfigValue('chatBackupThrottleInterval', 10_000); | |
| 56 | 57 | if (!backupFunctions.has(handle)) { |
| 57 | 58 | backupFunctions.set(handle, _.throttle(backupChat, throttleInterval, { leading: true, trailing: true })); |
| 58 | 59 | } |