2021-12-28 22:50:17 +01:00
|
|
|
const { CoverDestination, BookCoverAspectRatio, BookshelfView } = require('../utils/constants')
|
2021-10-01 01:52:32 +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'
|
2021-09-29 17:16:38 +02:00
|
|
|
|
2021-10-09 00:30:20 +02:00
|
|
|
// Misc/Unused
|
2021-09-05 02:58:39 +02:00
|
|
|
this.autoTagNew = false
|
|
|
|
this.newTagExpireDays = 15
|
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
|
2021-10-09 00:30:20 +02:00
|
|
|
|
|
|
|
// Metadata
|
2021-09-22 03:57:33 +02:00
|
|
|
this.coverDestination = CoverDestination.METADATA
|
2021-09-29 17:16:38 +02:00
|
|
|
this.saveMetadataFile = 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
|
|
|
|
// this.backupSchedule = '0 1 * * *' // If false then auto-backups are disabled (default every day at 1am)
|
|
|
|
this.backupSchedule = false
|
|
|
|
this.backupsToKeep = 2
|
|
|
|
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
|
|
|
|
2021-10-01 01:52:32 +02:00
|
|
|
this.logLevel = Logger.logLevel
|
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) {
|
|
|
|
this.autoTagNew = settings.autoTagNew
|
|
|
|
this.newTagExpireDays = settings.newTagExpireDays
|
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
|
|
|
|
|
2021-09-22 03:57:33 +02:00
|
|
|
this.coverDestination = settings.coverDestination || CoverDestination.METADATA
|
2021-09-29 17:16:38 +02:00
|
|
|
this.saveMetadataFile = !!settings.saveMetadataFile
|
|
|
|
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
|
|
|
|
this.backupMetadataCovers = settings.backupMetadataCovers !== false
|
|
|
|
|
2021-10-31 23:55:28 +01:00
|
|
|
this.loggerDailyLogsToKeep = settings.loggerDailyLogsToKeep || 7
|
|
|
|
this.loggerScannerLogsToKeep = settings.loggerScannerLogsToKeep || 2
|
|
|
|
|
2022-01-08 23:42:30 +01:00
|
|
|
this.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
|
|
|
|
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,
|
|
|
|
autoTagNew: this.autoTagNew,
|
|
|
|
newTagExpireDays: this.newTagExpireDays,
|
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,
|
2021-09-29 17:16:38 +02:00
|
|
|
coverDestination: this.coverDestination,
|
|
|
|
saveMetadataFile: !!this.saveMetadataFile,
|
|
|
|
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,
|
|
|
|
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,
|
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) {
|
|
|
|
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
|