Merge pull request #3264 from SillyTavern/backup-config-reorg Reorganize backup configs
Signed| @@ -84,6 +84,20 @@ autorun: true | |||
| 84 | # use if you don't have 'localhost' in your hosts file | 84 | # use if you don't have 'localhost' in your hosts file |
| 85 | avoidLocalhost: false | 85 | avoidLocalhost: false |
| 86 | 86 | ||
| 87 | ## BACKUP CONFIGURATION | ||
| 88 | backups: | ||
| 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 CONFIGURATION | 101 | # THUMBNAILING CONFIGURATION |
| 88 | thumbnails: | 102 | thumbnails: |
| 89 | # Enable thumbnail generation | 103 | # Enable thumbnail generation |
| @@ -102,14 +116,6 @@ thumbnails: | |||
| 102 | allowKeysExposure: false | 116 | allowKeysExposure: false |
| 103 | # Skip new default content checks | 117 | # Skip new default content checks |
| 104 | skipContentCheck: false | 118 | skipContentCheck: false |
| 105 | # Disable automatic chats backup | ||
| 106 | disableChatBackup: false | ||
| 107 | # Number of backups to keep for each chat and settings file | ||
| 108 | numberOfBackups: 50 | ||
| 109 | # Maximum number of chat backups to keep per user (starting from the most recent). Set to -1 to keep all backups. | ||
| 110 | maxTotalChatBackups: -1 | ||
| 111 | # Interval in milliseconds to throttle chat backups per user | ||
| 112 | chatBackupThrottleInterval: 10000 | ||
| 113 | # Allowed hosts for card downloads | 119 | # Allowed hosts for card downloads |
| 114 | whitelistImportDomains: | 120 | whitelistImportDomains: |
| 115 | - localhost | 121 | - localhost |
| @@ -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 | ]; |
| 48 | 68 | ||
| 49 | /** | 69 | /** |
| @@ -18,9 +18,9 @@ import { | |||
| 18 | formatBytes, | 18 | formatBytes, |
| 19 | } from '../util.js'; | 19 | } from '../util.js'; |
| 20 | 20 | ||
| 21 | const isBackupDisabled = getConfigValue('disableChatBackup', false); | 21 | const isBackupEnabled = !!getConfigValue('backups.chat.enabled', true); |
| 22 | const maxTotalChatBackups = Number(getConfigValue('maxTotalChatBackups', -1)); | 22 | const maxTotalChatBackups = Number(getConfigValue('backups.chat.maxTotalBackups', -1)); |
| 23 | const throttleInterval = getConfigValue('chatBackupThrottleInterval', 10_000); | 23 | const throttleInterval = Number(getConfigValue('backups.chat.throttleInterval', 10_000)); |
| 24 | 24 | ||
| 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); | |||
| 31 | function backupChat(directory, name, chat) { | 31 | function backupChat(directory, name, chat) { |
| 32 | try { | 32 | try { |
| 33 | 33 | ||
| 34 | if (isBackupDisabled) { | 34 | if (!isBackupEnabled) { |
| 35 | return; | 35 | return; |
| 36 | } | 36 | } |
| 37 | 37 | ||
| @@ -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 | */ |
| 394 | export function removeOldBackups(directory, prefix, limit = null) { | 394 | export 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)); |
| 396 | 396 | ||
| 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) { |