mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Move config reading to top-level
This commit is contained in:
@@ -11,6 +11,10 @@ import _ from 'lodash';
|
|||||||
import { jsonParser, urlencodedParser } from '../express-common.js';
|
import { jsonParser, urlencodedParser } from '../express-common.js';
|
||||||
import { getConfigValue, humanizedISO8601DateTime, tryParse, generateTimestamp, removeOldBackups } from '../util.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.
|
* Saves a chat to the backups directory.
|
||||||
* @param {string} directory The user's backups directory.
|
* @param {string} directory The user's backups directory.
|
||||||
@@ -19,7 +23,6 @@ import { getConfigValue, humanizedISO8601DateTime, tryParse, generateTimestamp,
|
|||||||
*/
|
*/
|
||||||
function backupChat(directory, name, chat) {
|
function backupChat(directory, name, chat) {
|
||||||
try {
|
try {
|
||||||
const isBackupDisabled = getConfigValue('disableChatBackup', false);
|
|
||||||
|
|
||||||
if (isBackupDisabled) {
|
if (isBackupDisabled) {
|
||||||
return;
|
return;
|
||||||
@@ -33,7 +36,6 @@ function backupChat(directory, name, chat) {
|
|||||||
|
|
||||||
removeOldBackups(directory, `chat_${name}_`);
|
removeOldBackups(directory, `chat_${name}_`);
|
||||||
|
|
||||||
const maxTotalChatBackups = Number(getConfigValue('maxTotalChatBackups', -1));
|
|
||||||
if (isNaN(maxTotalChatBackups) || maxTotalChatBackups < 0) {
|
if (isNaN(maxTotalChatBackups) || maxTotalChatBackups < 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -52,7 +54,6 @@ const backupFunctions = new Map();
|
|||||||
* @returns {function(string, string, string): void} Backup function
|
* @returns {function(string, string, string): void} Backup function
|
||||||
*/
|
*/
|
||||||
function getBackupFunction(handle) {
|
function getBackupFunction(handle) {
|
||||||
const throttleInterval = getConfigValue('chatBackupThrottleInterval', 10_000);
|
|
||||||
if (!backupFunctions.has(handle)) {
|
if (!backupFunctions.has(handle)) {
|
||||||
backupFunctions.set(handle, _.throttle(backupChat, throttleInterval, { leading: true, trailing: true }));
|
backupFunctions.set(handle, _.throttle(backupChat, throttleInterval, { leading: true, trailing: true }));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user