Start adding notification manager

This commit is contained in:
advplyr 2022-09-20 18:08:41 -05:00
parent 565bb4cd6b
commit 9a7503cde2
4 changed files with 61 additions and 4 deletions

View File

@ -23,6 +23,7 @@ const ApiRouter = require('./routers/ApiRouter')
const HlsRouter = require('./routers/HlsRouter')
const StaticRouter = require('./routers/StaticRouter')
const NotificationManager = require('./managers/NotificationManager')
const CoverManager = require('./managers/CoverManager')
const AbMergeManager = require('./managers/AbMergeManager')
const CacheManager = require('./managers/CacheManager')
@ -64,13 +65,14 @@ class Server {
this.auth = new Auth(this.db)
// Managers
this.notificationManager = new NotificationManager(this.db)
this.backupManager = new BackupManager(this.db, this.emitter.bind(this))
this.logManager = new LogManager(this.db)
this.cacheManager = new CacheManager()
this.abMergeManager = new AbMergeManager(this.db, this.clientEmitter.bind(this))
this.playbackSessionManager = new PlaybackSessionManager(this.db, this.emitter.bind(this), this.clientEmitter.bind(this))
this.coverManager = new CoverManager(this.db, this.cacheManager)
this.podcastManager = new PodcastManager(this.db, this.watcher, this.emitter.bind(this))
this.podcastManager = new PodcastManager(this.db, this.watcher, this.emitter.bind(this), this.notificationManager)
this.audioMetadataManager = new AudioMetadataMangaer(this.db, this.emitter.bind(this), this.clientEmitter.bind(this))
this.rssFeedManager = new RssFeedManager(this.db, this.emitter.bind(this))

View File

@ -0,0 +1,10 @@
const Logger = require("../Logger")
class NotificationManager {
constructor() { }
onNewPodcastEpisode(libraryItem, episode) {
Logger.debug(`[NotificationManager] onNewPodcastEpisode: Episode "${episode.title}" for podcast ${libraryItem.media.metadata.title}`)
}
}
module.exports = NotificationManager

View File

@ -13,10 +13,11 @@ const PodcastEpisode = require('../objects/entities/PodcastEpisode')
const AudioFile = require('../objects/files/AudioFile')
class PodcastManager {
constructor(db, watcher, emitter) {
constructor(db, watcher, emitter, notificationManager) {
this.db = db
this.watcher = watcher
this.emitter = emitter
this.notificationManager = notificationManager
this.downloadQueue = []
this.currentDownload = null
@ -122,8 +123,8 @@ class PodcastManager {
}
libraryItem.libraryFiles.push(libraryFile)
// Check setting maxEpisodesToKeep and remove episode if necessary
if (this.currentDownload.isAutoDownload) { // only applies for auto-downloaded episodes
if (this.currentDownload.isAutoDownload) {
// Check setting maxEpisodesToKeep and remove episode if necessary
if (libraryItem.media.maxEpisodesToKeep && libraryItem.media.episodesWithPubDate.length > libraryItem.media.maxEpisodesToKeep) {
Logger.info(`[PodcastManager] # of episodes (${libraryItem.media.episodesWithPubDate.length}) exceeds max episodes to keep (${libraryItem.media.maxEpisodesToKeep})`)
await this.removeOldestEpisode(libraryItem, podcastEpisode.id)
@ -133,6 +134,11 @@ class PodcastManager {
libraryItem.updatedAt = Date.now()
await this.db.updateLibraryItem(libraryItem)
this.emitter('item_updated', libraryItem.toJSONExpanded())
if (this.currentDownload.isAutoDownload) { // Notifications only for auto downloaded episodes
this.notificationManager.onNewPodcastEpisode(libraryItem, podcastEpisode)
}
return true
}

View File

@ -0,0 +1,39 @@
class Notification {
constructor(notification = null) {
this.id = null
this.eventName = ''
this.urls = []
this.titleTemplate = ''
this.bodyTemplate = ''
this.enabled = false
this.createdAt = null
if (notification) {
this.construct(notification)
}
}
construct(notification) {
this.id = notification.id
this.eventName = notification.eventName
this.urls = notification.urls || []
this.titleTemplate = notification.titleTemplate || ''
this.bodyTemplate = notification.bodyTemplate || ''
this.enabled = !!notification.enabled
this.createdAt = notification.createdAt
}
toJSON() {
return {
id: this.id,
eventName: this.eventName,
urls: this.urls,
titleTemplate: this.titleTemplate,
bodyTemplate: this.bodyTemplate,
enabled: this.enabled,
createdAt: this.createdAt
}
}
}
module.exports = Notification