Reorganize backup configs
| @@ -84,6 +84,20 @@ autorun: true | ||
| 84 | 84 | # use if you don't have 'localhost' in your hosts file |
| 85 | 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 | 101 | # THUMBNAILING CONFIGURATION |
| 88 | 102 | thumbnails: |
| 89 | 103 | # Enable thumbnail generation |
| @@ -102,14 +116,6 @@ thumbnails: | ||
| 102 | 116 | allowKeysExposure: false |
| 103 | 117 | # Skip new default content checks |
| 104 | 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 | 119 | # Allowed hosts for card downloads |
| 114 | 120 | whitelistImportDomains: |
| 115 | 121 | - localhost |
| @@ -44,6 +44,26 @@ const keyMigrationMap = [ | ||
| 44 | 44 | newKey: 'thumbnails.format', |
| 45 | 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 | 18 | formatBytes, |
| 19 | 19 | } from '../util.js'; |
| 20 | 20 | |
| 21 | 21 | const isBackupDisabledisBackupEnabled = !!getConfigValue('disableChatBackupbackups.chat.enabled', falsetrue); |
| 22 | 22 | const maxTotalChatBackups = Number(getConfigValue('maxTotalChatBackupsbackups.chat.maxTotalBackups', -1)); |
| 23 | 23 | const throttleInterval = Number(getConfigValue('chatBackupThrottleIntervalbackups.chat.throttleInterval', 10_000)); |
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * Saves a chat to the backups directory. |
| @@ -31,7 +31,7 @@ const throttleInterval = getConfigValue('chatBackupThrottleInterval', 10_000); | ||
| 31 | 31 | function backupChat(directory, name, chat) { |
| 32 | 32 | try { |
| 33 | 33 | |
| 34 | 34 | if (isBackupDisabled!isBackupEnabled) { |
| 35 | 35 | return; |
| 36 | 36 | } |
| 37 | 37 | |
| @@ -389,10 +389,10 @@ export function generateTimestamp() { | ||
| 389 | 389 | * Remove old backups with the given prefix from a specified directory. |
| 390 | 390 | * @param {string} directory The root directory to remove backups from. |
| 391 | 391 | * @param {string} prefix File prefix to filter backups by. |
| 392 | 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 | 394 | export function removeOldBackups(directory, prefix, limit = null) { |
| 395 | 395 | const MAX_BACKUPS = limit ?? Number(getConfigValue('backups.common.numberOfBackups', 50)); |
| 396 | 396 | |
| 397 | 397 | let files = fs.readdirSync(directory).filter(f => f.startsWith(prefix)); |
| 398 | 398 | if (files.length > MAX_BACKUPS) { |