mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-12 04:11:43 +00:00
Add: backup completion notification
This commit is contained in:
parent
2aabca906e
commit
b1adafedd2
4 changed files with 40 additions and 3 deletions
|
|
@ -68,7 +68,7 @@ class Server {
|
||||||
// Managers
|
// Managers
|
||||||
this.notificationManager = new NotificationManager()
|
this.notificationManager = new NotificationManager()
|
||||||
this.emailManager = new EmailManager()
|
this.emailManager = new EmailManager()
|
||||||
this.backupManager = new BackupManager()
|
this.backupManager = new BackupManager(this.notificationManager)
|
||||||
this.abMergeManager = new AbMergeManager()
|
this.abMergeManager = new AbMergeManager()
|
||||||
this.playbackSessionManager = new PlaybackSessionManager()
|
this.playbackSessionManager = new PlaybackSessionManager()
|
||||||
this.podcastManager = new PodcastManager(this.watcher, this.notificationManager)
|
this.podcastManager = new PodcastManager(this.watcher, this.notificationManager)
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,10 @@ const { getFileSize } = require('../utils/fileUtils')
|
||||||
const Backup = require('../objects/Backup')
|
const Backup = require('../objects/Backup')
|
||||||
|
|
||||||
class BackupManager {
|
class BackupManager {
|
||||||
constructor() {
|
constructor(notificationManager) {
|
||||||
this.ItemsMetadataPath = Path.join(global.MetadataPath, 'items')
|
this.ItemsMetadataPath = Path.join(global.MetadataPath, 'items')
|
||||||
this.AuthorsMetadataPath = Path.join(global.MetadataPath, 'authors')
|
this.AuthorsMetadataPath = Path.join(global.MetadataPath, 'authors')
|
||||||
|
this.notificationManager = notificationManager
|
||||||
|
|
||||||
this.scheduleTask = null
|
this.scheduleTask = null
|
||||||
|
|
||||||
|
|
@ -322,13 +323,18 @@ class BackupManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check remove oldest backup
|
// Check remove oldest backup
|
||||||
if (this.backups.length > this.backupsToKeep) {
|
const removeOldest = this.backups.length > this.backupsToKeep
|
||||||
|
if (removeOldest) {
|
||||||
this.backups.sort((a, b) => a.createdAt - b.createdAt)
|
this.backups.sort((a, b) => a.createdAt - b.createdAt)
|
||||||
|
|
||||||
const oldBackup = this.backups.shift()
|
const oldBackup = this.backups.shift()
|
||||||
Logger.debug(`[BackupManager] Removing old backup ${oldBackup.id}`)
|
Logger.debug(`[BackupManager] Removing old backup ${oldBackup.id}`)
|
||||||
this.removeBackup(oldBackup)
|
this.removeBackup(oldBackup)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Notifications only for auto downloaded episodes
|
||||||
|
this.notificationManager.onBackupCompleted(newBackup, this.backups.length, removeOldest)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,20 @@ class NotificationManager {
|
||||||
this.triggerNotification('onPodcastEpisodeDownloaded', eventData)
|
this.triggerNotification('onPodcastEpisodeDownloaded', eventData)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async onBackupCompleted(backup, totalBackupCount, removedOldest) {
|
||||||
|
if (!Database.notificationSettings.isUseable) return
|
||||||
|
|
||||||
|
Logger.debug(`[NotificationManager] onBackupCompleted: Backup completed`)
|
||||||
|
const eventData = {
|
||||||
|
completionTime: backup.createdAt,
|
||||||
|
backupPath: backup.fullPath,
|
||||||
|
backupSize: backup.fileSize,
|
||||||
|
backupCount: totalBackupCount || 'Invalid',
|
||||||
|
removedOldest: removedOldest || 'false'
|
||||||
|
}
|
||||||
|
this.triggerNotification('onBackupCompleted', eventData)
|
||||||
|
}
|
||||||
|
|
||||||
onTest() {
|
onTest() {
|
||||||
this.triggerNotification('onTest')
|
this.triggerNotification('onTest')
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,23 @@ module.exports.notificationData = {
|
||||||
episodeDescription: 'Some description of the podcast episode.'
|
episodeDescription: 'Some description of the podcast episode.'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'onBackupCompleted',
|
||||||
|
requiresLibrary: false,
|
||||||
|
description: 'Triggered when a backup is completed',
|
||||||
|
variables: ['completionTime', 'backupPath', 'backupSize', 'backupCount', 'removedOldest'],
|
||||||
|
defaults: {
|
||||||
|
title: 'Backup Completed',
|
||||||
|
body: 'Backup has been completed successfully.\n\nPath: {{backupPath}}\nSize: {{backupSize}}\nCount: {{backupCount}}\nRemoved Oldest: {{removedOldest}}'
|
||||||
|
},
|
||||||
|
testData: {
|
||||||
|
completionTime: '12:00 AM',
|
||||||
|
backupPath: 'path/to/backup',
|
||||||
|
backupSize: '1.23 MB',
|
||||||
|
backupCount: '1',
|
||||||
|
removedOldest: 'false'
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'onTest',
|
name: 'onTest',
|
||||||
requiresLibrary: false,
|
requiresLibrary: false,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue