mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-04-16 23:14:11 +02:00
Added an On Library Item notifcation event
This commit is contained in:
@@ -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')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user