mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-12 04:11:43 +00:00
Formatting updates
This commit is contained in:
parent
eabfa90121
commit
2aabca906e
1 changed files with 16 additions and 11 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
const Logger = require("../Logger")
|
const Logger = require('../Logger')
|
||||||
const SocketAuthority = require('../SocketAuthority')
|
const SocketAuthority = require('../SocketAuthority')
|
||||||
const Database = require('../Database')
|
const Database = require('../Database')
|
||||||
const { notificationData } = require('../utils/notifications')
|
const { notificationData } = require('../utils/notifications')
|
||||||
|
|
@ -52,7 +52,8 @@ class NotificationManager {
|
||||||
const success = intentionallyFail ? false : await this.sendNotification(notification, eventData)
|
const success = intentionallyFail ? false : await this.sendNotification(notification, eventData)
|
||||||
|
|
||||||
notification.updateNotificationFired(success)
|
notification.updateNotificationFired(success)
|
||||||
if (!success) { // Failed notification
|
if (!success) {
|
||||||
|
// Failed notification
|
||||||
if (notification.numConsecutiveFailedAttempts >= Database.notificationSettings.maxFailedAttempts) {
|
if (notification.numConsecutiveFailedAttempts >= Database.notificationSettings.maxFailedAttempts) {
|
||||||
Logger.error(`[NotificationManager] triggerNotification: ${notification.eventName}/${notification.id} reached max failed attempts`)
|
Logger.error(`[NotificationManager] triggerNotification: ${notification.eventName}/${notification.id} reached max failed attempts`)
|
||||||
notification.enabled = false
|
notification.enabled = false
|
||||||
|
|
@ -87,7 +88,8 @@ class NotificationManager {
|
||||||
// Delay between events then run next notification in queue
|
// Delay between events then run next notification in queue
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.sendingNotification = false
|
this.sendingNotification = false
|
||||||
if (this.notificationQueue.length) { // Send next notification in queue
|
if (this.notificationQueue.length) {
|
||||||
|
// Send next notification in queue
|
||||||
const nextNotificationEvent = this.notificationQueue.shift()
|
const nextNotificationEvent = this.notificationQueue.shift()
|
||||||
this.triggerNotification(nextNotificationEvent.eventName, nextNotificationEvent.eventData)
|
this.triggerNotification(nextNotificationEvent.eventName, nextNotificationEvent.eventData)
|
||||||
}
|
}
|
||||||
|
|
@ -95,7 +97,7 @@ class NotificationManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
sendTestNotification(notification) {
|
sendTestNotification(notification) {
|
||||||
const eventData = notificationData.events.find(e => e.name === notification.eventName)
|
const eventData = notificationData.events.find((e) => e.name === notification.eventName)
|
||||||
if (!eventData) {
|
if (!eventData) {
|
||||||
Logger.error(`[NotificationManager] sendTestNotification: Event not found ${notification.eventName}`)
|
Logger.error(`[NotificationManager] sendTestNotification: Event not found ${notification.eventName}`)
|
||||||
return false
|
return false
|
||||||
|
|
@ -106,13 +108,16 @@ class NotificationManager {
|
||||||
|
|
||||||
sendNotification(notification, eventData) {
|
sendNotification(notification, eventData) {
|
||||||
const payload = notification.getApprisePayload(eventData)
|
const payload = notification.getApprisePayload(eventData)
|
||||||
return axios.post(Database.notificationSettings.appriseApiUrl, payload, { timeout: 6000 }).then((response) => {
|
return axios
|
||||||
Logger.debug(`[NotificationManager] sendNotification: ${notification.eventName}/${notification.id} response=`, response.data)
|
.post(Database.notificationSettings.appriseApiUrl, payload, { timeout: 6000 })
|
||||||
return true
|
.then((response) => {
|
||||||
}).catch((error) => {
|
Logger.debug(`[NotificationManager] sendNotification: ${notification.eventName}/${notification.id} response=`, response.data)
|
||||||
Logger.error(`[NotificationManager] sendNotification: ${notification.eventName}/${notification.id} error=`, error)
|
return true
|
||||||
return false
|
})
|
||||||
})
|
.catch((error) => {
|
||||||
|
Logger.error(`[NotificationManager] sendNotification: ${notification.eventName}/${notification.id} error=`, error)
|
||||||
|
return false
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
module.exports = NotificationManager
|
module.exports = NotificationManager
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue