Move config reading to top-level

This commit is contained in:
Cohee
2024-12-08 14:05:14 +02:00
parent 7098e17d22
commit 210fac321b

View File

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