mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-08-02 22:51:45 +00:00
Merge b5feacb28f into 6caa1aa2da
This commit is contained in:
commit
c7e7a3c448
6 changed files with 69 additions and 12 deletions
|
|
@ -958,6 +958,7 @@
|
|||
"NotificationOnBackupCompletedDescription": "Triggered when a backup is completed",
|
||||
"NotificationOnBackupFailedDescription": "Triggered when a backup fails",
|
||||
"NotificationOnEpisodeDownloadedDescription": "Triggered when a podcast episode is auto-downloaded",
|
||||
"NotificationOnEpisodeManuallyDownloadedDescription": "Triggered when a podcast episode is manually downloaded",
|
||||
"NotificationOnRSSFeedDisabledDescription": "Triggered when automatic episode downloads are disabled due to too many failed attempts",
|
||||
"NotificationOnRSSFeedFailedDescription": "Triggered when the RSS feed request fails for an automatic episode download",
|
||||
"NotificationOnTestDescription": "Event for testing the notification system",
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ components:
|
|||
notificationEventName:
|
||||
type: string
|
||||
description: The name of the event the notification will fire on.
|
||||
enum: ['onPodcastEpisodeDownloaded', 'onBackupCompleted', 'onBackupFailed', 'onTest']
|
||||
enum: ['onPodcastEpisodeDownloaded', 'onPodcastEpisodeManuallyDownloaded', 'onBackupCompleted', 'onBackupFailed', 'onTest']
|
||||
urls:
|
||||
type: array
|
||||
items:
|
||||
|
|
|
|||
|
|
@ -3226,6 +3226,7 @@
|
|||
"description": "The name of the event the notification will fire on.",
|
||||
"enum": [
|
||||
"onPodcastEpisodeDownloaded",
|
||||
"onPodcastEpisodeManuallyDownloaded",
|
||||
"onBackupCompleted",
|
||||
"onBackupFailed",
|
||||
"onTest"
|
||||
|
|
|
|||
|
|
@ -18,18 +18,11 @@ class NotificationManager {
|
|||
*
|
||||
* @param {import('../models/LibraryItem')} libraryItem
|
||||
* @param {import('../models/PodcastEpisode')} episode
|
||||
* @returns {Promise<object>}
|
||||
*/
|
||||
async onPodcastEpisodeDownloaded(libraryItem, episode) {
|
||||
if (!Database.notificationSettings.isUseable) return
|
||||
|
||||
if (!Database.notificationSettings.getHasActiveNotificationsForEvent('onPodcastEpisodeDownloaded')) {
|
||||
Logger.debug(`[NotificationManager] onPodcastEpisodeDownloaded: No active notifications`)
|
||||
return
|
||||
}
|
||||
|
||||
Logger.debug(`[NotificationManager] onPodcastEpisodeDownloaded: Episode "${episode.title}" for podcast ${libraryItem.media.title}`)
|
||||
async getPodcastEpisodeDownloadedEventData(libraryItem, episode) {
|
||||
const library = await Database.libraryModel.findByPk(libraryItem.libraryId)
|
||||
const eventData = {
|
||||
return {
|
||||
libraryItemId: libraryItem.id,
|
||||
libraryId: libraryItem.libraryId,
|
||||
libraryName: library?.name || 'Unknown',
|
||||
|
|
@ -43,9 +36,44 @@ class NotificationManager {
|
|||
episodeSubtitle: episode.subtitle || '',
|
||||
episodeDescription: episode.description || ''
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {import('../models/LibraryItem')} libraryItem
|
||||
* @param {import('../models/PodcastEpisode')} episode
|
||||
*/
|
||||
async onPodcastEpisodeDownloaded(libraryItem, episode) {
|
||||
if (!Database.notificationSettings.isUseable) return
|
||||
|
||||
if (!Database.notificationSettings.getHasActiveNotificationsForEvent('onPodcastEpisodeDownloaded')) {
|
||||
Logger.debug(`[NotificationManager] onPodcastEpisodeDownloaded: No active notifications`)
|
||||
return
|
||||
}
|
||||
|
||||
Logger.debug(`[NotificationManager] onPodcastEpisodeDownloaded: Episode "${episode.title}" for podcast ${libraryItem.media.title}`)
|
||||
const eventData = await this.getPodcastEpisodeDownloadedEventData(libraryItem, episode)
|
||||
this.triggerNotification('onPodcastEpisodeDownloaded', eventData)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {import('../models/LibraryItem')} libraryItem
|
||||
* @param {import('../models/PodcastEpisode')} episode
|
||||
*/
|
||||
async onPodcastEpisodeManuallyDownloaded(libraryItem, episode) {
|
||||
if (!Database.notificationSettings.isUseable) return
|
||||
|
||||
if (!Database.notificationSettings.getHasActiveNotificationsForEvent('onPodcastEpisodeManuallyDownloaded')) {
|
||||
Logger.debug(`[NotificationManager] onPodcastEpisodeManuallyDownloaded: No active notifications`)
|
||||
return
|
||||
}
|
||||
|
||||
Logger.debug(`[NotificationManager] onPodcastEpisodeManuallyDownloaded: Episode "${episode.title}" for podcast ${libraryItem.media.title}`)
|
||||
const eventData = await this.getPodcastEpisodeDownloadedEventData(libraryItem, episode)
|
||||
this.triggerNotification('onPodcastEpisodeManuallyDownloaded', eventData)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {import('../objects/Backup')} backup
|
||||
|
|
|
|||
|
|
@ -256,8 +256,9 @@ class PodcastManager {
|
|||
SocketAuthority.emitter('episode_added', podcastEpisodeExpanded)
|
||||
|
||||
if (this.currentDownload.isAutoDownload) {
|
||||
// Notifications only for auto downloaded episodes
|
||||
NotificationManager.onPodcastEpisodeDownloaded(libraryItem, podcastEpisode)
|
||||
} else {
|
||||
NotificationManager.onPodcastEpisodeManuallyDownloaded(libraryItem, podcastEpisode)
|
||||
}
|
||||
|
||||
return true
|
||||
|
|
|
|||
|
|
@ -28,6 +28,32 @@ module.exports.notificationData = {
|
|||
episodeDescription: 'Some description of the podcast episode.'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'onPodcastEpisodeManuallyDownloaded',
|
||||
requiresLibrary: true,
|
||||
libraryMediaType: 'podcast',
|
||||
description: 'Triggered when a podcast episode is manually downloaded',
|
||||
descriptionKey: 'NotificationOnEpisodeManuallyDownloadedDescription',
|
||||
variables: ['libraryItemId', 'libraryId', 'podcastTitle', 'podcastAuthor', 'podcastDescription', 'podcastGenres', 'episodeTitle', 'episodeSubtitle', 'episodeDescription', 'libraryName', 'episodeId', 'mediaTags'],
|
||||
defaults: {
|
||||
title: 'New {{podcastTitle}} Episode!',
|
||||
body: '{{episodeTitle}} has been added to {{libraryName}} library.'
|
||||
},
|
||||
testData: {
|
||||
libraryItemId: 'li_notification_test',
|
||||
libraryId: 'lib_test',
|
||||
libraryName: 'Podcasts',
|
||||
mediaTags: 'TestTag1, TestTag2',
|
||||
podcastTitle: 'Abs Test Podcast',
|
||||
podcastAuthor: 'Audiobookshelf',
|
||||
podcastDescription: 'Description of the Abs Test Podcast belongs here.',
|
||||
podcastGenres: 'TestGenre1, TestGenre2',
|
||||
episodeId: 'ep_notification_test',
|
||||
episodeTitle: 'Successful Test Episode',
|
||||
episodeSubtitle: 'Episode Subtitle',
|
||||
episodeDescription: 'Some description of the podcast episode.'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'onBackupCompleted',
|
||||
requiresLibrary: false,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue