2022-10-22 16:01:00 +02:00
|
|
|
const { BookshelfView } = require('../../utils/constants')
|
2022-07-17 01:54:34 +02:00
|
|
|
const { isNullOrNaN } = require('../../utils')
|
2022-04-15 00:15:52 +02:00
|
|
|
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'
|
2022-07-19 00:19:16 +02:00
|
|
|
this.tokenSecret = null
|
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
|
2022-09-11 22:35:06 +02:00
|
|
|
this.scannerUseTone = 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-10-22 16:01:00 +02:00
|
|
|
this.backupSchedule = false // If false then auto-backups are disabled
|
2021-10-09 00:30:20 +02:00
|
|
|
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
|
|
|
|
|
2022-08-14 01:18:42 +02:00
|
|
|
// Bookshelf Display
|
|
|
|
this.homeBookshelfView = BookshelfView.STANDARD
|
2022-10-22 16:13:20 +02:00
|
|
|
this.bookshelfView = BookshelfView.DETAIL
|
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-10-28 00:50:56 +02:00
|
|
|
this.sortingPrefixes = ['the']
|
2022-03-31 22:07:50 +02:00
|
|
|
|
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-11-09 01:09:07 +01:00
|
|
|
this.language = 'en-us'
|
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) {
|
2022-07-19 00:19:16 +02:00
|
|
|
this.tokenSecret = settings.tokenSecret
|
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
|
2022-09-11 22:35:06 +02:00
|
|
|
this.scannerUseTone = !!settings.scannerUseTone
|
2021-11-26 01:39:02 +01:00
|
|
|
|
2022-04-12 23:05:16 +02:00
|
|
|
this.storeCoverWithItem = !!settings.storeCoverWithItem
|
|
|
|
this.storeMetadataWithItem = !!settings.storeMetadataWithItem
|
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-08-14 01:18:42 +02:00
|
|
|
this.homeBookshelfView = settings.homeBookshelfView || BookshelfView.STANDARD
|
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-10-28 00:50:56 +02:00
|
|
|
this.sortingPrefixes = settings.sortingPrefixes || ['the']
|
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'
|
2022-11-09 01:09:07 +01:00
|
|
|
this.language = settings.language || 'en-us'
|
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
|
|
|
|
2022-08-14 01:18:42 +02:00
|
|
|
// Migrations
|
|
|
|
if (settings.storeCoverWithBook != undefined) { // storeCoverWithBook was renamed to storeCoverWithItem in 2.0.0
|
|
|
|
this.storeCoverWithItem = !!settings.storeCoverWithBook
|
|
|
|
}
|
|
|
|
if (settings.storeMetadataWithBook != undefined) { // storeMetadataWithBook was renamed to storeMetadataWithItem in 2.0.0
|
|
|
|
this.storeMetadataWithItem = !!settings.storeMetadataWithBook
|
|
|
|
}
|
|
|
|
if (settings.homeBookshelfView == undefined) { // homeBookshelfView was added in 2.1.3
|
|
|
|
this.homeBookshelfView = settings.bookshelfView
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-07-19 00:19:16 +02:00
|
|
|
toJSON() { // Use toJSONForBrowser if sending to client
|
2021-09-05 02:58:39 +02:00
|
|
|
return {
|
|
|
|
id: this.id,
|
2022-07-19 00:19:16 +02:00
|
|
|
tokenSecret: this.tokenSecret, // Do not return to client
|
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-09-11 22:35:06 +02:00
|
|
|
scannerUseTone: this.scannerUseTone,
|
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,
|
2022-08-14 01:18:42 +02:00
|
|
|
homeBookshelfView: this.homeBookshelfView,
|
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,
|
2022-11-09 01:09:07 +01:00
|
|
|
language: this.language,
|
2021-11-16 03:09:42 +01:00
|
|
|
logLevel: this.logLevel,
|
|
|
|
version: this.version
|
2021-09-05 02:58:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-19 00:19:16 +02:00
|
|
|
toJSONForBrowser() {
|
|
|
|
const json = this.toJSON()
|
|
|
|
delete json.tokenSecret
|
|
|
|
return json
|
|
|
|
}
|
|
|
|
|
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
|