mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-07-23 04:14:46 +02:00
Add:Notification settings, notification manager trigger #996
This commit is contained in:
parent
9a7503cde2
commit
ff04eb8d5e
9 changed files with 239 additions and 5 deletions
|
@ -1,10 +1,12 @@
|
|||
class Notification {
|
||||
constructor(notification = null) {
|
||||
this.id = null
|
||||
this.libraryId = null
|
||||
this.eventName = ''
|
||||
this.urls = []
|
||||
this.titleTemplate = ''
|
||||
this.bodyTemplate = ''
|
||||
this.type = 'info'
|
||||
this.enabled = false
|
||||
|
||||
this.createdAt = null
|
||||
|
@ -16,10 +18,12 @@ class Notification {
|
|||
|
||||
construct(notification) {
|
||||
this.id = notification.id
|
||||
this.libraryId = notification.libraryId || null
|
||||
this.eventName = notification.eventName
|
||||
this.urls = notification.urls || []
|
||||
this.titleTemplate = notification.titleTemplate || ''
|
||||
this.bodyTemplate = notification.bodyTemplate || ''
|
||||
this.type = notification.type || 'info'
|
||||
this.enabled = !!notification.enabled
|
||||
this.createdAt = notification.createdAt
|
||||
}
|
||||
|
@ -27,13 +31,33 @@ class Notification {
|
|||
toJSON() {
|
||||
return {
|
||||
id: this.id,
|
||||
libraryId: this.libraryId,
|
||||
eventName: this.eventName,
|
||||
urls: this.urls,
|
||||
titleTemplate: this.titleTemplate,
|
||||
bodyTemplate: this.bodyTemplate,
|
||||
enabled: this.enabled,
|
||||
type: this.type,
|
||||
createdAt: this.createdAt
|
||||
}
|
||||
}
|
||||
|
||||
parseTitleTemplate(data) {
|
||||
// TODO: Implement template parsing
|
||||
return 'Test Title'
|
||||
}
|
||||
|
||||
parseBodyTemplate(data) {
|
||||
// TODO: Implement template parsing
|
||||
return 'Test Body'
|
||||
}
|
||||
|
||||
getApprisePayload(data) {
|
||||
return {
|
||||
urls: this.urls,
|
||||
title: this.parseTitleTemplate(data),
|
||||
body: this.parseBodyTemplate(data)
|
||||
}
|
||||
}
|
||||
}
|
||||
module.exports = Notification
|
45
server/objects/settings/NotificationSettings.js
Normal file
45
server/objects/settings/NotificationSettings.js
Normal file
|
@ -0,0 +1,45 @@
|
|||
class NotificationSettings {
|
||||
constructor(settings = null) {
|
||||
this.id = 'notification-settings'
|
||||
this.appriseType = 'api'
|
||||
this.appriseApiUrl = null
|
||||
this.notifications = []
|
||||
|
||||
if (settings) {
|
||||
this.construct(settings)
|
||||
}
|
||||
}
|
||||
|
||||
construct(settings) {
|
||||
this.appriseType = settings.appriseType
|
||||
this.appriseApiUrl = settings.appriseApiUrl || null
|
||||
this.notifications = (settings.notifications || []).map(n => ({ ...n }))
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return {
|
||||
id: this.id,
|
||||
appriseType: this.appriseType,
|
||||
appriseApiUrl: this.appriseApiUrl,
|
||||
notifications: this.notifications.map(n => n.toJSON())
|
||||
}
|
||||
}
|
||||
|
||||
get isUseable() {
|
||||
return !!this.appriseApiUrl
|
||||
}
|
||||
|
||||
getNotificationsForEvent(eventName) {
|
||||
return this.notifications.filter(n => n.eventName === eventName)
|
||||
}
|
||||
|
||||
update(payload) {
|
||||
if (!payload) return false
|
||||
if (payload.appriseApiUrl !== this.appriseApiUrl) {
|
||||
this.appriseApiUrl = payload.appriseApiUrl || null
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
module.exports = NotificationSettings
|
Loading…
Add table
Add a link
Reference in a new issue