Added an On Library Item notifcation event

This commit is contained in:
zipben
2025-06-04 11:20:18 +00:00
parent c377b57601
commit bfbe5aa91e
10 changed files with 3530 additions and 3804 deletions

View File

@@ -3,6 +3,7 @@ const Logger = require('../Logger')
const SocketAuthority = require('../SocketAuthority')
const Database = require('../Database')
const { notificationData } = require('../utils/notifications')
const Json = require('../libs/archiver/lib/plugins/json')
class NotificationManager {
constructor() {
@@ -90,6 +91,30 @@ class NotificationManager {
this.triggerNotification('onBackupFailed', eventData)
}
/**
* @param {import('../models/LibraryItem')} libraryItem
*/
async onLibraryItemAdded(libraryItem) {
try {
if (!Database.notificationSettings.isUseable) return
if (!Database.notificationSettings.getHasActiveNotificationsForEvent('onLibraryItemAdded')) {
Logger.debug(`[NotificationManager] onLibraryItemAdded: No active notifications`)
return
}
const eventData = {
itemTitle: libraryItem.title,
itemAuthor: libraryItem.authorNamesFirstLast,
mediaType: libraryItem.mediaType
}
this.triggerNotification('onLibraryItemAdded', eventData)
} catch (error) {
Logger.error('[NotificationManager] Error in onLibraryItemAdded:', error)
}
}
onTest() {
this.triggerNotification('onTest')
}