mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-27 03:31:46 +00:00
Merge branch 'master' into social
This commit is contained in:
commit
12b7976ef3
245 changed files with 11554 additions and 3676 deletions
106
server/objects/settings/NotificationSettings.js
Normal file
106
server/objects/settings/NotificationSettings.js
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
const Logger = require('../../Logger')
|
||||
const Notification = require('../Notification')
|
||||
const { isNullOrNaN } = require('../../utils')
|
||||
|
||||
class NotificationSettings {
|
||||
constructor(settings = null) {
|
||||
this.id = 'notification-settings'
|
||||
this.appriseType = 'api'
|
||||
this.appriseApiUrl = null
|
||||
this.notifications = []
|
||||
this.maxFailedAttempts = 5
|
||||
this.maxNotificationQueue = 20 // once reached events will be ignored
|
||||
this.notificationDelay = 1000 // ms delay between firing notifications
|
||||
|
||||
if (settings) {
|
||||
this.construct(settings)
|
||||
}
|
||||
}
|
||||
|
||||
construct(settings) {
|
||||
this.appriseType = settings.appriseType
|
||||
this.appriseApiUrl = settings.appriseApiUrl || null
|
||||
this.notifications = (settings.notifications || []).map(n => new Notification(n))
|
||||
this.maxFailedAttempts = settings.maxFailedAttempts || 5
|
||||
this.maxNotificationQueue = settings.maxNotificationQueue || 20
|
||||
this.notificationDelay = settings.notificationDelay || 1000
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return {
|
||||
id: this.id,
|
||||
appriseType: this.appriseType,
|
||||
appriseApiUrl: this.appriseApiUrl,
|
||||
notifications: this.notifications.map(n => n.toJSON()),
|
||||
maxFailedAttempts: this.maxFailedAttempts,
|
||||
maxNotificationQueue: this.maxNotificationQueue,
|
||||
notificationDelay: this.notificationDelay
|
||||
}
|
||||
}
|
||||
|
||||
get isUseable() {
|
||||
return !!this.appriseApiUrl
|
||||
}
|
||||
|
||||
getActiveNotificationsForEvent(eventName) {
|
||||
return this.notifications.filter(n => n.eventName === eventName && n.enabled)
|
||||
}
|
||||
|
||||
getNotification(id) {
|
||||
return this.notifications.find(n => n.id === id)
|
||||
}
|
||||
|
||||
removeNotification(id) {
|
||||
if (this.notifications.some(n => n.id === id)) {
|
||||
this.notifications = this.notifications.filter(n => n.id !== id)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
update(payload) {
|
||||
if (!payload) return false
|
||||
|
||||
var hasUpdates = false
|
||||
if (payload.appriseApiUrl !== this.appriseApiUrl) {
|
||||
this.appriseApiUrl = payload.appriseApiUrl || null
|
||||
hasUpdates = true
|
||||
}
|
||||
|
||||
const _maxFailedAttempts = isNullOrNaN(payload.maxFailedAttempts) ? 5 : Number(payload.maxFailedAttempts)
|
||||
if (_maxFailedAttempts !== this.maxFailedAttempts) {
|
||||
this.maxFailedAttempts = _maxFailedAttempts
|
||||
hasUpdates = true
|
||||
}
|
||||
|
||||
const _maxNotificationQueue = isNullOrNaN(payload.maxNotificationQueue) ? 20 : Number(payload.maxNotificationQueue)
|
||||
if (_maxNotificationQueue !== this.maxNotificationQueue) {
|
||||
this.maxNotificationQueue = _maxNotificationQueue
|
||||
hasUpdates = true
|
||||
}
|
||||
|
||||
return hasUpdates
|
||||
}
|
||||
|
||||
createNotification(payload) {
|
||||
if (!payload) return false
|
||||
if (!payload.eventName || !payload.urls.length) return false
|
||||
|
||||
const notification = new Notification()
|
||||
notification.setData(payload)
|
||||
this.notifications.push(notification)
|
||||
return true
|
||||
}
|
||||
|
||||
updateNotification(payload) {
|
||||
if (!payload) return false
|
||||
const notification = this.notifications.find(n => n.id === payload.id)
|
||||
if (!notification) {
|
||||
Logger.error(`[NotificationSettings] updateNotification: Notification not found ${payload.id}`)
|
||||
return false
|
||||
}
|
||||
|
||||
return notification.update(payload)
|
||||
}
|
||||
}
|
||||
module.exports = NotificationSettings
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
const { BookCoverAspectRatio, BookshelfView } = require('../../utils/constants')
|
||||
const { BookshelfView } = require('../../utils/constants')
|
||||
const { isNullOrNaN } = require('../../utils')
|
||||
const Logger = require('../../Logger')
|
||||
|
||||
|
|
@ -17,7 +17,8 @@ class ServerSettings {
|
|||
this.scannerDisableWatcher = false
|
||||
this.scannerPreferOverdriveMediaMarker = false
|
||||
this.scannerUseSingleThreadedProber = true
|
||||
this.scannerMaxThreads = 0 // 0 = defaults to CPUs * 2
|
||||
this.scannerMaxThreads = 0 // Currently not being used
|
||||
this.scannerUseTone = false
|
||||
|
||||
// Metadata - choose to store inside users library item folder
|
||||
this.storeCoverWithItem = false
|
||||
|
|
@ -28,8 +29,7 @@ class ServerSettings {
|
|||
this.rateLimitLoginWindow = 10 * 60 * 1000 // 10 Minutes
|
||||
|
||||
// Backups
|
||||
// this.backupSchedule = '30 1 * * *' // If false then auto-backups are disabled (default every day at 1:30am)
|
||||
this.backupSchedule = false
|
||||
this.backupSchedule = false // If false then auto-backups are disabled
|
||||
this.backupsToKeep = 2
|
||||
this.maxBackupSize = 1
|
||||
this.backupMetadataCovers = true
|
||||
|
|
@ -38,26 +38,23 @@ class ServerSettings {
|
|||
this.loggerDailyLogsToKeep = 7
|
||||
this.loggerScannerLogsToKeep = 2
|
||||
|
||||
// Cover
|
||||
// TODO: Remove after mobile apps are configured to use library server settings
|
||||
this.coverAspectRatio = BookCoverAspectRatio.SQUARE
|
||||
|
||||
// Bookshelf Display
|
||||
this.homeBookshelfView = BookshelfView.STANDARD
|
||||
this.bookshelfView = BookshelfView.STANDARD
|
||||
this.bookshelfView = BookshelfView.DETAIL
|
||||
|
||||
// Podcasts
|
||||
this.podcastEpisodeSchedule = '0 * * * *' // Every hour
|
||||
|
||||
// Sorting
|
||||
this.sortingIgnorePrefix = false
|
||||
this.sortingPrefixes = ['the', 'a']
|
||||
this.sortingPrefixes = ['the']
|
||||
|
||||
// Misc Flags
|
||||
this.chromecastEnabled = false
|
||||
this.sharedListeningStats = false
|
||||
this.enableEReader = false
|
||||
this.dateFormat = 'MM/dd/yyyy'
|
||||
this.language = 'en-us'
|
||||
|
||||
this.logLevel = Logger.logLevel
|
||||
|
||||
|
|
@ -83,6 +80,7 @@ class ServerSettings {
|
|||
this.scannerUseSingleThreadedProber = true
|
||||
}
|
||||
this.scannerMaxThreads = isNullOrNaN(settings.scannerMaxThreads) ? 0 : Number(settings.scannerMaxThreads)
|
||||
this.scannerUseTone = !!settings.scannerUseTone
|
||||
|
||||
this.storeCoverWithItem = !!settings.storeCoverWithItem
|
||||
this.storeMetadataWithItem = !!settings.storeMetadataWithItem
|
||||
|
|
@ -98,16 +96,16 @@ class ServerSettings {
|
|||
this.loggerDailyLogsToKeep = settings.loggerDailyLogsToKeep || 7
|
||||
this.loggerScannerLogsToKeep = settings.loggerScannerLogsToKeep || 2
|
||||
|
||||
this.coverAspectRatio = !isNaN(settings.coverAspectRatio) ? settings.coverAspectRatio : BookCoverAspectRatio.SQUARE
|
||||
this.homeBookshelfView = settings.homeBookshelfView || BookshelfView.STANDARD
|
||||
this.bookshelfView = settings.bookshelfView || BookshelfView.STANDARD
|
||||
|
||||
this.sortingIgnorePrefix = !!settings.sortingIgnorePrefix
|
||||
this.sortingPrefixes = settings.sortingPrefixes || ['the', 'a']
|
||||
this.sortingPrefixes = settings.sortingPrefixes || ['the']
|
||||
this.chromecastEnabled = !!settings.chromecastEnabled
|
||||
this.sharedListeningStats = !!settings.sharedListeningStats
|
||||
this.enableEReader = !!settings.enableEReader
|
||||
this.dateFormat = settings.dateFormat || 'MM/dd/yyyy'
|
||||
this.language = settings.language || 'en-us'
|
||||
this.logLevel = settings.logLevel || Logger.logLevel
|
||||
this.version = settings.version || null
|
||||
|
||||
|
|
@ -141,6 +139,7 @@ class ServerSettings {
|
|||
scannerPreferOverdriveMediaMarker: this.scannerPreferOverdriveMediaMarker,
|
||||
scannerUseSingleThreadedProber: this.scannerUseSingleThreadedProber,
|
||||
scannerMaxThreads: this.scannerMaxThreads,
|
||||
scannerUseTone: this.scannerUseTone,
|
||||
storeCoverWithItem: this.storeCoverWithItem,
|
||||
storeMetadataWithItem: this.storeMetadataWithItem,
|
||||
rateLimitLoginRequests: this.rateLimitLoginRequests,
|
||||
|
|
@ -151,7 +150,6 @@ class ServerSettings {
|
|||
backupMetadataCovers: this.backupMetadataCovers,
|
||||
loggerDailyLogsToKeep: this.loggerDailyLogsToKeep,
|
||||
loggerScannerLogsToKeep: this.loggerScannerLogsToKeep,
|
||||
coverAspectRatio: this.coverAspectRatio,
|
||||
homeBookshelfView: this.homeBookshelfView,
|
||||
bookshelfView: this.bookshelfView,
|
||||
sortingIgnorePrefix: this.sortingIgnorePrefix,
|
||||
|
|
@ -160,6 +158,7 @@ class ServerSettings {
|
|||
sharedListeningStats: this.sharedListeningStats,
|
||||
enableEReader: this.enableEReader,
|
||||
dateFormat: this.dateFormat,
|
||||
language: this.language,
|
||||
logLevel: this.logLevel,
|
||||
version: this.version
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue