2022-04-15 00:15:52 +02:00
|
|
|
const { BookCoverAspectRatio } = require('../../utils/constants')
|
|
|
|
|
|
|
|
class LibrarySettings {
|
|
|
|
constructor(settings) {
|
2022-08-13 20:56:37 +02:00
|
|
|
this.coverAspectRatio = BookCoverAspectRatio.SQUARE
|
2022-04-15 00:15:52 +02:00
|
|
|
this.disableWatcher = false
|
2022-04-27 02:36:29 +02:00
|
|
|
this.skipMatchingMediaWithAsin = false
|
|
|
|
this.skipMatchingMediaWithIsbn = false
|
2022-08-17 01:24:47 +02:00
|
|
|
this.autoScanCronExpression = null
|
2023-06-10 19:46:57 +02:00
|
|
|
this.audiobooksOnly = false
|
2022-04-15 00:15:52 +02:00
|
|
|
|
|
|
|
if (settings) {
|
|
|
|
this.construct(settings)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
construct(settings) {
|
2022-08-13 20:56:37 +02:00
|
|
|
this.coverAspectRatio = !isNaN(settings.coverAspectRatio) ? settings.coverAspectRatio : BookCoverAspectRatio.SQUARE
|
2022-04-15 00:15:52 +02:00
|
|
|
this.disableWatcher = !!settings.disableWatcher
|
2022-04-27 02:36:29 +02:00
|
|
|
this.skipMatchingMediaWithAsin = !!settings.skipMatchingMediaWithAsin
|
|
|
|
this.skipMatchingMediaWithIsbn = !!settings.skipMatchingMediaWithIsbn
|
2022-08-17 01:24:47 +02:00
|
|
|
this.autoScanCronExpression = settings.autoScanCronExpression || null
|
2023-06-10 19:46:57 +02:00
|
|
|
this.audiobooksOnly = !!settings.audiobooksOnly
|
2022-04-15 00:15:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
toJSON() {
|
|
|
|
return {
|
2022-08-13 20:56:37 +02:00
|
|
|
coverAspectRatio: this.coverAspectRatio,
|
2022-04-27 02:36:29 +02:00
|
|
|
disableWatcher: this.disableWatcher,
|
|
|
|
skipMatchingMediaWithAsin: this.skipMatchingMediaWithAsin,
|
2022-08-17 01:24:47 +02:00
|
|
|
skipMatchingMediaWithIsbn: this.skipMatchingMediaWithIsbn,
|
2023-06-10 19:46:57 +02:00
|
|
|
autoScanCronExpression: this.autoScanCronExpression,
|
|
|
|
audiobooksOnly: this.audiobooksOnly
|
2022-04-15 00:15:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
update(payload) {
|
2023-06-10 19:46:57 +02:00
|
|
|
let hasUpdates = false
|
2022-04-15 00:15:52 +02:00
|
|
|
for (const key in payload) {
|
|
|
|
if (this[key] !== payload[key]) {
|
|
|
|
this[key] = payload[key]
|
|
|
|
hasUpdates = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return hasUpdates
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = LibrarySettings
|