Move config reading to top-level

210fac321b222420a26b6b37a320c02560e89094

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +4 -3Showing whitespace changes
src/endpoints/chats.js+4 -3
@@ -11,6 +11,10 @@ import _ from 'lodash';
1111import { jsonParser, urlencodedParser } from '../express-common.js';
1212import { getConfigValue, humanizedISO8601DateTime, tryParse, generateTimestamp, removeOldBackups } from '../util.js';
1313
14+const isBackupDisabled = getConfigValue('disableChatBackup', false);
15+const maxTotalChatBackups = Number(getConfigValue('maxTotalChatBackups', -1));
16+const throttleInterval = getConfigValue('chatBackupThrottleInterval', 10_000);
17+
1418/**
1519 * Saves a chat to the backups directory.
1620 * @param {string} directory The user's backups directory.
@@ -19,7 +23,6 @@ import { getConfigValue, humanizedISO8601DateTime, tryParse, generateTimestamp,
1923 */
2024function backupChat(directory, name, chat) {
2125 try {
22- const isBackupDisabled = getConfigValue('disableChatBackup', false);
2326
2427 if (isBackupDisabled) {
2528 return;
@@ -33,7 +36,6 @@ function backupChat(directory, name, chat) {
3336
3437 removeOldBackups(directory, `chat_${name}_`);
3538
36- const maxTotalChatBackups = Number(getConfigValue('maxTotalChatBackups', -1));
3739 if (isNaN(maxTotalChatBackups) || maxTotalChatBackups < 0) {
3840 return;
3941 }
@@ -52,7 +54,6 @@ const backupFunctions = new Map();
5254 * @returns {function(string, string, string): void} Backup function
5355 */
5456function getBackupFunction(handle) {
55- const throttleInterval = getConfigValue('chatBackupThrottleInterval', 10_000);
5657 if (!backupFunctions.has(handle)) {
5758 backupFunctions.set(handle, _.throttle(backupChat, throttleInterval, { leading: true, trailing: true }));
5859 }