audiobookshelf/server/objects/Notification.js

63 lines
1.4 KiB
JavaScript
Raw Normal View History

2022-09-21 01:08:41 +02:00
class Notification {
constructor(notification = null) {
this.id = null
this.libraryId = null
2022-09-21 01:08:41 +02:00
this.eventName = ''
this.urls = []
this.titleTemplate = ''
this.bodyTemplate = ''
this.type = 'info'
2022-09-21 01:08:41 +02:00
this.enabled = false
this.createdAt = null
if (notification) {
this.construct(notification)
}
}
construct(notification) {
this.id = notification.id
this.libraryId = notification.libraryId || null
2022-09-21 01:08:41 +02:00
this.eventName = notification.eventName
this.urls = notification.urls || []
this.titleTemplate = notification.titleTemplate || ''
this.bodyTemplate = notification.bodyTemplate || ''
this.type = notification.type || 'info'
2022-09-21 01:08:41 +02:00
this.enabled = !!notification.enabled
this.createdAt = notification.createdAt
}
toJSON() {
return {
id: this.id,
libraryId: this.libraryId,
2022-09-21 01:08:41 +02:00
eventName: this.eventName,
urls: this.urls,
titleTemplate: this.titleTemplate,
bodyTemplate: this.bodyTemplate,
enabled: this.enabled,
type: this.type,
2022-09-21 01:08:41 +02:00
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)
}
}
2022-09-21 01:08:41 +02:00
}
module.exports = Notification