Merge pull request #3264 from SillyTavern/backup-config-reorg Reorganize backup configs

d13ec29158d5a7c92be51966b9fb09b6efe5c4ad

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

Signed
4 files changed, +40 -14Ignore whitespace
default/config.yaml+14 -8
@@ -84,6 +84,20 @@ autorun: true
84# use if you don't have 'localhost' in your hosts file84# use if you don't have 'localhost' in your hosts file
85avoidLocalhost: false85avoidLocalhost: false
8686
87## BACKUP CONFIGURATION
88backups:
89 # Common settings for all backup types
90 common:
91 # Number of backups to keep for each chat and settings file
92 numberOfBackups: 50
93 chat:
94 # Enable automatic chat backups
95 enabled: true
96 # Maximum number of chat backups to keep per user (starting from the most recent). Set to -1 to keep all backups.
97 maxTotalBackups: -1
98 # Interval in milliseconds to throttle chat backups per user
99 throttleInterval: 10000
100
87# THUMBNAILING CONFIGURATION101# THUMBNAILING CONFIGURATION
88thumbnails:102thumbnails:
89 # Enable thumbnail generation103 # Enable thumbnail generation
@@ -102,14 +116,6 @@ thumbnails:
102allowKeysExposure: false116allowKeysExposure: false
103# Skip new default content checks117# Skip new default content checks
104skipContentCheck: false118skipContentCheck: false
105# Disable automatic chats backup
106disableChatBackup: false
107# Number of backups to keep for each chat and settings file
108numberOfBackups: 50
109# Maximum number of chat backups to keep per user (starting from the most recent). Set to -1 to keep all backups.
110maxTotalChatBackups: -1
111# Interval in milliseconds to throttle chat backups per user
112chatBackupThrottleInterval: 10000
113# Allowed hosts for card downloads119# Allowed hosts for card downloads
114whitelistImportDomains:120whitelistImportDomains:
115 - localhost121 - localhost
post-install.js+20 -0
@@ -44,6 +44,26 @@ const keyMigrationMap = [
44 newKey: 'thumbnails.format',44 newKey: 'thumbnails.format',
45 migrate: (value) => (value ? 'png' : 'jpg'),45 migrate: (value) => (value ? 'png' : 'jpg'),
46 },46 },
47 {
48 oldKey: 'disableChatBackup',
49 newKey: 'backups.chat.enabled',
50 migrate: (value) => !value,
51 },
52 {
53 oldKey: 'numberOfBackups',
54 newKey: 'backups.common.numberOfBackups',
55 migrate: (value) => value,
56 },
57 {
58 oldKey: 'maxTotalChatBackups',
59 newKey: 'backups.chat.maxTotalBackups',
60 migrate: (value) => value,
61 },
62 {
63 oldKey: 'chatBackupThrottleInterval',
64 newKey: 'backups.chat.throttleInterval',
65 migrate: (value) => value,
66 },
47];67];
4868
49/**69/**
src/endpoints/chats.js+4 -4
@@ -18,9 +18,9 @@ import {
18 formatBytes,18 formatBytes,
19} from '../util.js';19} from '../util.js';
2020
21const isBackupDisabled = getConfigValue('disableChatBackup', false);21const isBackupEnabled = !!getConfigValue('backups.chat.enabled', true);
22const maxTotalChatBackups = Number(getConfigValue('maxTotalChatBackups', -1));22const maxTotalChatBackups = Number(getConfigValue('backups.chat.maxTotalBackups', -1));
23const throttleInterval = getConfigValue('chatBackupThrottleInterval', 10_000);23const throttleInterval = Number(getConfigValue('backups.chat.throttleInterval', 10_000));
2424
25/**25/**
26 * Saves a chat to the backups directory.26 * Saves a chat to the backups directory.
@@ -31,7 +31,7 @@ const throttleInterval = getConfigValue('chatBackupThrottleInterval', 10_000);
31function backupChat(directory, name, chat) {31function backupChat(directory, name, chat) {
32 try {32 try {
3333
34 if (isBackupDisabled) {34 if (!isBackupEnabled) {
35 return;35 return;
36 }36 }
3737
src/util.js+2 -2
@@ -389,10 +389,10 @@ export function generateTimestamp() {
389 * Remove old backups with the given prefix from a specified directory.389 * Remove old backups with the given prefix from a specified directory.
390 * @param {string} directory The root directory to remove backups from.390 * @param {string} directory The root directory to remove backups from.
391 * @param {string} prefix File prefix to filter backups by.391 * @param {string} prefix File prefix to filter backups by.
392 * @param {number?} limit Maximum number of backups to keep. If null, the limit is determined by the `numberOfBackups` config value.392 * @param {number?} limit Maximum number of backups to keep. If null, the limit is determined by the `backups.common.numberOfBackups` config value.
393 */393 */
394export function removeOldBackups(directory, prefix, limit = null) {394export function removeOldBackups(directory, prefix, limit = null) {
395 const MAX_BACKUPS = limit ?? Number(getConfigValue('numberOfBackups', 50));395 const MAX_BACKUPS = limit ?? Number(getConfigValue('backups.common.numberOfBackups', 50));
396396
397 let files = fs.readdirSync(directory).filter(f => f.startsWith(prefix));397 let files = fs.readdirSync(directory).filter(f => f.startsWith(prefix));
398 if (files.length > MAX_BACKUPS) {398 if (files.length > MAX_BACKUPS) {