mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-22 00:07:52 +01:00
Start adding notification manager
This commit is contained in:
parent
565bb4cd6b
commit
9a7503cde2
@ -23,6 +23,7 @@ const ApiRouter = require('./routers/ApiRouter')
|
|||||||
const HlsRouter = require('./routers/HlsRouter')
|
const HlsRouter = require('./routers/HlsRouter')
|
||||||
const StaticRouter = require('./routers/StaticRouter')
|
const StaticRouter = require('./routers/StaticRouter')
|
||||||
|
|
||||||
|
const NotificationManager = require('./managers/NotificationManager')
|
||||||
const CoverManager = require('./managers/CoverManager')
|
const CoverManager = require('./managers/CoverManager')
|
||||||
const AbMergeManager = require('./managers/AbMergeManager')
|
const AbMergeManager = require('./managers/AbMergeManager')
|
||||||
const CacheManager = require('./managers/CacheManager')
|
const CacheManager = require('./managers/CacheManager')
|
||||||
@ -64,13 +65,14 @@ class Server {
|
|||||||
this.auth = new Auth(this.db)
|
this.auth = new Auth(this.db)
|
||||||
|
|
||||||
// Managers
|
// Managers
|
||||||
|
this.notificationManager = new NotificationManager(this.db)
|
||||||
this.backupManager = new BackupManager(this.db, this.emitter.bind(this))
|
this.backupManager = new BackupManager(this.db, this.emitter.bind(this))
|
||||||
this.logManager = new LogManager(this.db)
|
this.logManager = new LogManager(this.db)
|
||||||
this.cacheManager = new CacheManager()
|
this.cacheManager = new CacheManager()
|
||||||
this.abMergeManager = new AbMergeManager(this.db, this.clientEmitter.bind(this))
|
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.playbackSessionManager = new PlaybackSessionManager(this.db, this.emitter.bind(this), this.clientEmitter.bind(this))
|
||||||
this.coverManager = new CoverManager(this.db, this.cacheManager)
|
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.audioMetadataManager = new AudioMetadataMangaer(this.db, this.emitter.bind(this), this.clientEmitter.bind(this))
|
||||||
this.rssFeedManager = new RssFeedManager(this.db, this.emitter.bind(this))
|
this.rssFeedManager = new RssFeedManager(this.db, this.emitter.bind(this))
|
||||||
|
|
||||||
|
10
server/managers/NotificationManager.js
Normal file
10
server/managers/NotificationManager.js
Normal 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
|
@ -13,10 +13,11 @@ const PodcastEpisode = require('../objects/entities/PodcastEpisode')
|
|||||||
const AudioFile = require('../objects/files/AudioFile')
|
const AudioFile = require('../objects/files/AudioFile')
|
||||||
|
|
||||||
class PodcastManager {
|
class PodcastManager {
|
||||||
constructor(db, watcher, emitter) {
|
constructor(db, watcher, emitter, notificationManager) {
|
||||||
this.db = db
|
this.db = db
|
||||||
this.watcher = watcher
|
this.watcher = watcher
|
||||||
this.emitter = emitter
|
this.emitter = emitter
|
||||||
|
this.notificationManager = notificationManager
|
||||||
|
|
||||||
this.downloadQueue = []
|
this.downloadQueue = []
|
||||||
this.currentDownload = null
|
this.currentDownload = null
|
||||||
@ -122,8 +123,8 @@ class PodcastManager {
|
|||||||
}
|
}
|
||||||
libraryItem.libraryFiles.push(libraryFile)
|
libraryItem.libraryFiles.push(libraryFile)
|
||||||
|
|
||||||
// Check setting maxEpisodesToKeep and remove episode if necessary
|
if (this.currentDownload.isAutoDownload) {
|
||||||
if (this.currentDownload.isAutoDownload) { // only applies for auto-downloaded episodes
|
// Check setting maxEpisodesToKeep and remove episode if necessary
|
||||||
if (libraryItem.media.maxEpisodesToKeep && libraryItem.media.episodesWithPubDate.length > libraryItem.media.maxEpisodesToKeep) {
|
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})`)
|
Logger.info(`[PodcastManager] # of episodes (${libraryItem.media.episodesWithPubDate.length}) exceeds max episodes to keep (${libraryItem.media.maxEpisodesToKeep})`)
|
||||||
await this.removeOldestEpisode(libraryItem, podcastEpisode.id)
|
await this.removeOldestEpisode(libraryItem, podcastEpisode.id)
|
||||||
@ -133,6 +134,11 @@ class PodcastManager {
|
|||||||
libraryItem.updatedAt = Date.now()
|
libraryItem.updatedAt = Date.now()
|
||||||
await this.db.updateLibraryItem(libraryItem)
|
await this.db.updateLibraryItem(libraryItem)
|
||||||
this.emitter('item_updated', libraryItem.toJSONExpanded())
|
this.emitter('item_updated', libraryItem.toJSONExpanded())
|
||||||
|
|
||||||
|
if (this.currentDownload.isAutoDownload) { // Notifications only for auto downloaded episodes
|
||||||
|
this.notificationManager.onNewPodcastEpisode(libraryItem, podcastEpisode)
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
39
server/objects/Notification.js
Normal file
39
server/objects/Notification.js
Normal 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
|
Loading…
Reference in New Issue
Block a user