2022-04-15 00:15:52 +02:00
|
|
|
const { BookCoverAspectRatio, BookshelfView } = require('../../utils/constants')
|
|
|
|
const Logger = require('../../Logger')
|
2021-09-22 03:57:33 +02:00
|
|
|
|
2021-09-05 02:58:39 +02:00
|
|
|
class ServerSettings {
|
|
|
|
constructor(settings) {
|
|
|
|
this.id = 'server-settings'
|
2021-09-29 17:16:38 +02:00
|
|
|
|
2021-10-09 00:30:20 +02:00
|
|
|
// Scanner
|
2021-09-05 02:58:39 +02:00
|
|
|
this.scannerParseSubtitle = false
|
2021-10-05 05:11:42 +02:00
|
|
|
this.scannerFindCovers = false
|
2022-01-09 00:03:33 +01:00
|
|
|
this.scannerCoverProvider = 'google'
|
2021-11-25 03:15:50 +01:00
|
|
|
this.scannerPreferAudioMetadata = false
|
|
|
|
this.scannerPreferOpfMetadata = false
|
2022-05-23 04:56:51 +02:00
|
|
|
this.scannerPreferMatchedMetadata = false
|
2022-06-17 10:26:10 +02:00
|
|
|
this.scannerDisableWatcher = false
|
2022-06-12 08:17:22 +02:00
|
|
|
this.scannerPreferOverdriveMediaMarker = false
|
2021-10-09 00:30:20 +02:00
|
|
|
|
2022-04-12 23:05:16 +02:00
|
|
|
// Metadata - choose to store inside users library item folder
|
|
|
|
this.storeCoverWithItem = false
|
|
|
|
this.storeMetadataWithItem = false
|
2021-10-09 00:30:20 +02:00
|
|
|
|
|
|
|
// Security/Rate limits
|
2021-09-29 17:16:38 +02:00
|
|
|
this.rateLimitLoginRequests = 10
|
|
|
|
this.rateLimitLoginWindow = 10 * 60 * 1000 // 10 Minutes
|
2021-10-09 00:30:20 +02:00
|
|
|
|
|
|
|
// Backups
|
2022-07-06 00:38:17 +02:00
|
|
|
// this.backupSchedule = '30 1 * * *' // If false then auto-backups are disabled (default every day at 1:30am)
|
2021-10-09 00:30:20 +02:00
|
|
|
this.backupSchedule = false
|
|
|
|
this.backupsToKeep = 2
|
2022-04-23 19:19:31 +02:00
|
|
|
this.maxBackupSize = 1
|
2021-10-09 00:30:20 +02:00
|
|
|
this.backupMetadataCovers = true
|
|
|
|
|
2021-10-31 23:55:28 +01:00
|
|
|
// Logger
|
|
|
|
this.loggerDailyLogsToKeep = 7
|
|
|
|
this.loggerScannerLogsToKeep = 2
|
|
|
|
|
2021-12-02 22:49:03 +01:00
|
|
|
// Cover
|
2022-01-08 23:42:30 +01:00
|
|
|
this.coverAspectRatio = BookCoverAspectRatio.SQUARE
|
2021-12-28 22:50:17 +01:00
|
|
|
this.bookshelfView = BookshelfView.STANDARD
|
2021-12-02 22:49:03 +01:00
|
|
|
|
2022-03-26 17:59:34 +01:00
|
|
|
// Podcasts
|
|
|
|
this.podcastEpisodeSchedule = '0 * * * *' // Every hour
|
|
|
|
|
2022-05-20 23:34:51 +02:00
|
|
|
// Sorting
|
2022-02-13 22:00:59 +01:00
|
|
|
this.sortingIgnorePrefix = false
|
2022-03-31 22:07:50 +02:00
|
|
|
this.sortingPrefixes = ['the', 'a']
|
|
|
|
|
2022-05-20 23:34:51 +02:00
|
|
|
// Misc Flags
|
2022-02-23 00:33:55 +01:00
|
|
|
this.chromecastEnabled = false
|
2022-05-20 23:34:51 +02:00
|
|
|
this.enableEReader = false
|
2022-06-18 02:09:03 +02:00
|
|
|
this.dateFormat = 'MM/dd/yyyy'
|
2022-05-20 23:34:51 +02:00
|
|
|
|
2021-10-01 01:52:32 +02:00
|
|
|
this.logLevel = Logger.logLevel
|
2022-05-20 23:34:51 +02:00
|
|
|
|
2021-11-16 03:09:42 +01:00
|
|
|
this.version = null
|
2021-09-05 02:58:39 +02:00
|
|
|
|
|
|
|
if (settings) {
|
|
|
|
this.construct(settings)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
construct(settings) {
|
2021-10-05 05:11:42 +02:00
|
|
|
this.scannerFindCovers = !!settings.scannerFindCovers
|
2022-01-09 00:03:33 +01:00
|
|
|
this.scannerCoverProvider = settings.scannerCoverProvider || 'google'
|
2021-09-05 02:58:39 +02:00
|
|
|
this.scannerParseSubtitle = settings.scannerParseSubtitle
|
2021-11-26 01:39:02 +01:00
|
|
|
this.scannerPreferAudioMetadata = !!settings.scannerPreferAudioMetadata
|
|
|
|
this.scannerPreferOpfMetadata = !!settings.scannerPreferOpfMetadata
|
2022-05-23 04:56:51 +02:00
|
|
|
this.scannerPreferMatchedMetadata = !!settings.scannerPreferMatchedMetadata
|
2022-02-24 00:52:21 +01:00
|
|
|
this.scannerDisableWatcher = !!settings.scannerDisableWatcher
|
2022-06-12 08:17:22 +02:00
|
|
|
this.scannerPreferOverdriveMediaMarker = !!settings.scannerPreferOverdriveMediaMarker
|
2021-11-26 01:39:02 +01:00
|
|
|
|
2022-04-12 23:05:16 +02:00
|
|
|
this.storeCoverWithItem = !!settings.storeCoverWithItem
|
|
|
|
if (settings.storeCoverWithBook != undefined) { // storeCoverWithBook was old name of setting < v2
|
|
|
|
this.storeCoverWithItem = !!settings.storeCoverWithBook
|
|
|
|
}
|
|
|
|
this.storeMetadataWithItem = !!settings.storeMetadataWithItem
|
|
|
|
if (settings.storeMetadataWithBook != undefined) { // storeMetadataWithBook was old name of setting < v2
|
|
|
|
this.storeMetadataWithItem = !!settings.storeMetadataWithBook
|
2022-02-27 19:47:56 +01:00
|
|
|
}
|
|
|
|
|
2021-09-29 17:16:38 +02:00
|
|
|
this.rateLimitLoginRequests = !isNaN(settings.rateLimitLoginRequests) ? Number(settings.rateLimitLoginRequests) : 10
|
|
|
|
this.rateLimitLoginWindow = !isNaN(settings.rateLimitLoginWindow) ? Number(settings.rateLimitLoginWindow) : 10 * 60 * 1000 // 10 Minutes
|
2021-10-09 00:30:20 +02:00
|
|
|
|
|
|
|
this.backupSchedule = settings.backupSchedule || false
|
|
|
|
this.backupsToKeep = settings.backupsToKeep || 2
|
2022-04-29 23:42:40 +02:00
|
|
|
this.maxBackupSize = settings.maxBackupSize || 1
|
2021-10-09 00:30:20 +02:00
|
|
|
this.backupMetadataCovers = settings.backupMetadataCovers !== false
|
|
|
|
|
2021-10-31 23:55:28 +01:00
|
|
|
this.loggerDailyLogsToKeep = settings.loggerDailyLogsToKeep || 7
|
|
|
|
this.loggerScannerLogsToKeep = settings.loggerScannerLogsToKeep || 2
|
|
|
|
|
2022-02-01 23:58:11 +01:00
|
|
|
this.coverAspectRatio = !isNaN(settings.coverAspectRatio) ? settings.coverAspectRatio : BookCoverAspectRatio.SQUARE
|
2021-12-28 22:50:17 +01:00
|
|
|
this.bookshelfView = settings.bookshelfView || BookshelfView.STANDARD
|
2021-12-02 22:49:03 +01:00
|
|
|
|
2022-02-13 22:00:59 +01:00
|
|
|
this.sortingIgnorePrefix = !!settings.sortingIgnorePrefix
|
2022-03-31 22:07:50 +02:00
|
|
|
this.sortingPrefixes = settings.sortingPrefixes || ['the', 'a']
|
2022-02-23 00:33:55 +01:00
|
|
|
this.chromecastEnabled = !!settings.chromecastEnabled
|
2022-05-20 23:34:51 +02:00
|
|
|
this.enableEReader = !!settings.enableEReader
|
2022-06-18 02:09:03 +02:00
|
|
|
this.dateFormat = settings.dateFormat || 'MM/dd/yyyy'
|
2021-10-01 01:52:32 +02:00
|
|
|
this.logLevel = settings.logLevel || Logger.logLevel
|
2021-11-16 03:09:42 +01:00
|
|
|
this.version = settings.version || null
|
2021-10-01 01:52:32 +02:00
|
|
|
|
|
|
|
if (this.logLevel !== Logger.logLevel) {
|
|
|
|
Logger.setLogLevel(this.logLevel)
|
|
|
|
}
|
2021-09-05 02:58:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
toJSON() {
|
|
|
|
return {
|
|
|
|
id: this.id,
|
2021-10-05 05:11:42 +02:00
|
|
|
scannerFindCovers: this.scannerFindCovers,
|
2022-01-09 00:03:33 +01:00
|
|
|
scannerCoverProvider: this.scannerCoverProvider,
|
2021-09-22 03:57:33 +02:00
|
|
|
scannerParseSubtitle: this.scannerParseSubtitle,
|
2021-11-26 01:39:02 +01:00
|
|
|
scannerPreferAudioMetadata: this.scannerPreferAudioMetadata,
|
|
|
|
scannerPreferOpfMetadata: this.scannerPreferOpfMetadata,
|
2022-05-23 04:56:51 +02:00
|
|
|
scannerPreferMatchedMetadata: this.scannerPreferMatchedMetadata,
|
2022-02-24 00:52:21 +01:00
|
|
|
scannerDisableWatcher: this.scannerDisableWatcher,
|
2022-06-12 08:17:22 +02:00
|
|
|
scannerPreferOverdriveMediaMarker: this.scannerPreferOverdriveMediaMarker,
|
2022-04-12 23:05:16 +02:00
|
|
|
storeCoverWithItem: this.storeCoverWithItem,
|
|
|
|
storeMetadataWithItem: this.storeMetadataWithItem,
|
2021-09-29 17:16:38 +02:00
|
|
|
rateLimitLoginRequests: this.rateLimitLoginRequests,
|
2021-10-01 01:52:32 +02:00
|
|
|
rateLimitLoginWindow: this.rateLimitLoginWindow,
|
2021-10-09 00:30:20 +02:00
|
|
|
backupSchedule: this.backupSchedule,
|
|
|
|
backupsToKeep: this.backupsToKeep,
|
2022-04-23 19:19:31 +02:00
|
|
|
maxBackupSize: this.maxBackupSize,
|
2021-10-09 00:30:20 +02:00
|
|
|
backupMetadataCovers: this.backupMetadataCovers,
|
2021-10-31 23:55:28 +01:00
|
|
|
loggerDailyLogsToKeep: this.loggerDailyLogsToKeep,
|
|
|
|
loggerScannerLogsToKeep: this.loggerScannerLogsToKeep,
|
2021-12-02 22:49:03 +01:00
|
|
|
coverAspectRatio: this.coverAspectRatio,
|
2021-12-28 22:50:17 +01:00
|
|
|
bookshelfView: this.bookshelfView,
|
2022-02-13 22:00:59 +01:00
|
|
|
sortingIgnorePrefix: this.sortingIgnorePrefix,
|
2022-03-31 22:07:50 +02:00
|
|
|
sortingPrefixes: [...this.sortingPrefixes],
|
2022-02-23 00:33:55 +01:00
|
|
|
chromecastEnabled: this.chromecastEnabled,
|
2022-05-20 23:34:51 +02:00
|
|
|
enableEReader: this.enableEReader,
|
2022-06-17 10:26:10 +02:00
|
|
|
dateFormat: this.dateFormat,
|
2021-11-16 03:09:42 +01:00
|
|
|
logLevel: this.logLevel,
|
|
|
|
version: this.version
|
2021-09-05 02:58:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
update(payload) {
|
|
|
|
var hasUpdates = false
|
|
|
|
for (const key in payload) {
|
2022-03-31 22:07:50 +02:00
|
|
|
if (key === 'sortingPrefixes' && payload[key] && payload[key].length) {
|
|
|
|
var prefixesCleaned = payload[key].filter(prefix => !!prefix).map(prefix => prefix.toLowerCase())
|
|
|
|
if (prefixesCleaned.join(',') !== this[key].join(',')) {
|
|
|
|
this[key] = [...prefixesCleaned]
|
|
|
|
hasUpdates = true
|
|
|
|
}
|
|
|
|
} else if (this[key] !== payload[key]) {
|
2021-10-01 01:52:32 +02:00
|
|
|
if (key === 'logLevel') {
|
|
|
|
Logger.setLogLevel(payload[key])
|
|
|
|
}
|
2021-09-05 02:58:39 +02:00
|
|
|
this[key] = payload[key]
|
|
|
|
hasUpdates = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return hasUpdates
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = ServerSettings
|