diff --git a/default/config.yaml b/default/config.yaml index b18d9a2a5..a9d38a4d0 100644 --- a/default/config.yaml +++ b/default/config.yaml @@ -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 diff --git a/post-install.js b/post-install.js index d3e16a498..97745bb15 100644 --- a/post-install.js +++ b/post-install.js @@ -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, + }, ]; /** diff --git a/src/endpoints/chats.js b/src/endpoints/chats.js index f5312b4bb..62c790400 100644 --- a/src/endpoints/chats.js +++ b/src/endpoints/chats.js @@ -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; } diff --git a/src/util.js b/src/util.js index 37b6bdd6f..0fe03e76c 100644 --- a/src/util.js +++ b/src/util.js @@ -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) {