Reorganize backup configs

9db9c5c9caba50c93e478ca3f5bf7d0120f28b60

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

4 files changed, +40 -14Ignore whitespace
default/config.yaml+14 -8
@@ -84,6 +84,20 @@ autorun: true
8484# use if you don't have 'localhost' in your hosts file
8585avoidLocalhost: false
8686
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+
87101# THUMBNAILING CONFIGURATION
88102thumbnails:
89103 # Enable thumbnail generation
@@ -102,14 +116,6 @@ thumbnails:
102116allowKeysExposure: false
103117# Skip new default content checks
104118skipContentCheck: 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
113119# Allowed hosts for card downloads
114120whitelistImportDomains:
115121 - localhost
post-install.js+20 -0
@@ -44,6 +44,26 @@ const keyMigrationMap = [
4444 newKey: 'thumbnails.format',
4545 migrate: (value) => (value ? 'png' : 'jpg'),
4646 },
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+ },
4767];
4868
4969/**
src/endpoints/chats.js+4 -4
@@ -18,9 +18,9 @@ import {
1818 formatBytes,
1919} from '../util.js';
2020
2121const isBackupDisabledisBackupEnabled = !!getConfigValue('disableChatBackupbackups.chat.enabled', falsetrue);
2222const maxTotalChatBackups = Number(getConfigValue('maxTotalChatBackupsbackups.chat.maxTotalBackups', -1));
2323const throttleInterval = Number(getConfigValue('chatBackupThrottleIntervalbackups.chat.throttleInterval', 10_000));
2424
2525/**
2626 * Saves a chat to the backups directory.
@@ -31,7 +31,7 @@ const throttleInterval = getConfigValue('chatBackupThrottleInterval', 10_000);
3131function backupChat(directory, name, chat) {
3232 try {
3333
3434 if (isBackupDisabled!isBackupEnabled) {
3535 return;
3636 }
3737
src/util.js+2 -2
@@ -389,10 +389,10 @@ export function generateTimestamp() {
389389 * Remove old backups with the given prefix from a specified directory.
390390 * @param {string} directory The root directory to remove backups from.
391391 * @param {string} prefix File prefix to filter backups by.
392392 * @param {number?} limit Maximum number of backups to keep. If null, the limit is determined by the `backups.common.numberOfBackups` config value.
393393 */
394394export function removeOldBackups(directory, prefix, limit = null) {
395395 const MAX_BACKUPS = limit ?? Number(getConfigValue('backups.common.numberOfBackups', 50));
396396
397397 let files = fs.readdirSync(directory).filter(f => f.startsWith(prefix));
398398 if (files.length > MAX_BACKUPS) {