mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-23 07:27:41 +01:00
Merge pull request #3264 from SillyTavern/backup-config-reorg
Reorganize backup configs
This commit is contained in:
commit
d13ec29158
@ -84,6 +84,20 @@ autorun: true
|
||||
# use if you don't have 'localhost' in your hosts file
|
||||
avoidLocalhost: false
|
||||
|
||||
## BACKUP CONFIGURATION
|
||||
backups:
|
||||
# Common settings for all backup types
|
||||
common:
|
||||
# Number of backups to keep for each chat and settings file
|
||||
numberOfBackups: 50
|
||||
chat:
|
||||
# Enable automatic chat backups
|
||||
enabled: true
|
||||
# Maximum number of chat backups to keep per user (starting from the most recent). Set to -1 to keep all backups.
|
||||
maxTotalBackups: -1
|
||||
# Interval in milliseconds to throttle chat backups per user
|
||||
throttleInterval: 10000
|
||||
|
||||
# THUMBNAILING CONFIGURATION
|
||||
thumbnails:
|
||||
# Enable thumbnail generation
|
||||
@ -102,14 +116,6 @@ thumbnails:
|
||||
allowKeysExposure: false
|
||||
# Skip new default content checks
|
||||
skipContentCheck: false
|
||||
# Disable automatic chats backup
|
||||
disableChatBackup: false
|
||||
# Number of backups to keep for each chat and settings file
|
||||
numberOfBackups: 50
|
||||
# Maximum number of chat backups to keep per user (starting from the most recent). Set to -1 to keep all backups.
|
||||
maxTotalChatBackups: -1
|
||||
# Interval in milliseconds to throttle chat backups per user
|
||||
chatBackupThrottleInterval: 10000
|
||||
# Allowed hosts for card downloads
|
||||
whitelistImportDomains:
|
||||
- localhost
|
||||
|
@ -44,6 +44,26 @@ const keyMigrationMap = [
|
||||
newKey: 'thumbnails.format',
|
||||
migrate: (value) => (value ? 'png' : 'jpg'),
|
||||
},
|
||||
{
|
||||
oldKey: 'disableChatBackup',
|
||||
newKey: 'backups.chat.enabled',
|
||||
migrate: (value) => !value,
|
||||
},
|
||||
{
|
||||
oldKey: 'numberOfBackups',
|
||||
newKey: 'backups.common.numberOfBackups',
|
||||
migrate: (value) => value,
|
||||
},
|
||||
{
|
||||
oldKey: 'maxTotalChatBackups',
|
||||
newKey: 'backups.chat.maxTotalBackups',
|
||||
migrate: (value) => value,
|
||||
},
|
||||
{
|
||||
oldKey: 'chatBackupThrottleInterval',
|
||||
newKey: 'backups.chat.throttleInterval',
|
||||
migrate: (value) => value,
|
||||
},
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -18,9 +18,9 @@ import {
|
||||
formatBytes,
|
||||
} from '../util.js';
|
||||
|
||||
const isBackupDisabled = getConfigValue('disableChatBackup', false);
|
||||
const maxTotalChatBackups = Number(getConfigValue('maxTotalChatBackups', -1));
|
||||
const throttleInterval = getConfigValue('chatBackupThrottleInterval', 10_000);
|
||||
const isBackupEnabled = !!getConfigValue('backups.chat.enabled', true);
|
||||
const maxTotalChatBackups = Number(getConfigValue('backups.chat.maxTotalBackups', -1));
|
||||
const throttleInterval = Number(getConfigValue('backups.chat.throttleInterval', 10_000));
|
||||
|
||||
/**
|
||||
* Saves a chat to the backups directory.
|
||||
@ -31,7 +31,7 @@ const throttleInterval = getConfigValue('chatBackupThrottleInterval', 10_000);
|
||||
function backupChat(directory, name, chat) {
|
||||
try {
|
||||
|
||||
if (isBackupDisabled) {
|
||||
if (!isBackupEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -389,10 +389,10 @@ export function generateTimestamp() {
|
||||
* Remove old backups with the given prefix from a specified directory.
|
||||
* @param {string} directory The root directory to remove backups from.
|
||||
* @param {string} prefix File prefix to filter backups by.
|
||||
* @param {number?} limit Maximum number of backups to keep. If null, the limit is determined by the `numberOfBackups` config value.
|
||||
* @param {number?} limit Maximum number of backups to keep. If null, the limit is determined by the `backups.common.numberOfBackups` config value.
|
||||
*/
|
||||
export function removeOldBackups(directory, prefix, limit = null) {
|
||||
const MAX_BACKUPS = limit ?? Number(getConfigValue('numberOfBackups', 50));
|
||||
const MAX_BACKUPS = limit ?? Number(getConfigValue('backups.common.numberOfBackups', 50));
|
||||
|
||||
let files = fs.readdirSync(directory).filter(f => f.startsWith(prefix));
|
||||
if (files.length > MAX_BACKUPS) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user