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
|
# use if you don't have 'localhost' in your hosts file
|
||||||
avoidLocalhost: false
|
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
|
# THUMBNAILING CONFIGURATION
|
||||||
thumbnails:
|
thumbnails:
|
||||||
# Enable thumbnail generation
|
# Enable thumbnail generation
|
||||||
@ -102,14 +116,6 @@ thumbnails:
|
|||||||
allowKeysExposure: false
|
allowKeysExposure: false
|
||||||
# Skip new default content checks
|
# Skip new default content checks
|
||||||
skipContentCheck: false
|
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
|
# Allowed hosts for card downloads
|
||||||
whitelistImportDomains:
|
whitelistImportDomains:
|
||||||
- localhost
|
- localhost
|
||||||
|
@ -44,6 +44,26 @@ const keyMigrationMap = [
|
|||||||
newKey: 'thumbnails.format',
|
newKey: 'thumbnails.format',
|
||||||
migrate: (value) => (value ? 'png' : 'jpg'),
|
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,
|
formatBytes,
|
||||||
} from '../util.js';
|
} from '../util.js';
|
||||||
|
|
||||||
const isBackupDisabled = getConfigValue('disableChatBackup', false);
|
const isBackupEnabled = !!getConfigValue('backups.chat.enabled', true);
|
||||||
const maxTotalChatBackups = Number(getConfigValue('maxTotalChatBackups', -1));
|
const maxTotalChatBackups = Number(getConfigValue('backups.chat.maxTotalBackups', -1));
|
||||||
const throttleInterval = getConfigValue('chatBackupThrottleInterval', 10_000);
|
const throttleInterval = Number(getConfigValue('backups.chat.throttleInterval', 10_000));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves a chat to the backups directory.
|
* Saves a chat to the backups directory.
|
||||||
@ -31,7 +31,7 @@ const throttleInterval = getConfigValue('chatBackupThrottleInterval', 10_000);
|
|||||||
function backupChat(directory, name, chat) {
|
function backupChat(directory, name, chat) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (isBackupDisabled) {
|
if (!isBackupEnabled) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,10 +389,10 @@ export function generateTimestamp() {
|
|||||||
* Remove old backups with the given prefix from a specified directory.
|
* Remove old backups with the given prefix from a specified directory.
|
||||||
* @param {string} directory The root directory to remove backups from.
|
* @param {string} directory The root directory to remove backups from.
|
||||||
* @param {string} prefix File prefix to filter backups by.
|
* @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) {
|
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));
|
let files = fs.readdirSync(directory).filter(f => f.startsWith(prefix));
|
||||||
if (files.length > MAX_BACKUPS) {
|
if (files.length > MAX_BACKUPS) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user