Move config reading to top-level

210fac321b222420a26b6b37a320c02560e89094

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

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