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
|
2024-05-26 23:01:08 +02:00
|
|
|
this.epubsAllowScriptedContent = false
|
2024-03-12 17:04:26 +01:00
|
|
|
this.hideSingleBookSeries = false // Do not show series that only have 1 book
|
|
|
|
this.onlyShowLaterBooksInContinueSeries = false // Skip showing books that are earlier than the max sequence read
|
2023-11-12 14:30:23 +01:00
|
|
|
this.metadataPrecedence = ['folderStructure', 'audioMetatags', 'nfoFile', 'txtFiles', 'opfFile', 'absMetadata']
|
2024-01-05 07:45:35 +01:00
|
|
|
this.podcastSearchRegion = 'us'
|
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
|
2024-05-26 23:01:08 +02:00
|
|
|
this.epubsAllowScriptedContent = !!settings.epubsAllowScriptedContent
|
2023-06-30 00:55:17 +02:00
|
|
|
this.hideSingleBookSeries = !!settings.hideSingleBookSeries
|
2024-03-12 17:04:26 +01:00
|
|
|
this.onlyShowLaterBooksInContinueSeries = !!settings.onlyShowLaterBooksInContinueSeries
|
2023-10-09 00:10:43 +02:00
|
|
|
if (settings.metadataPrecedence) {
|
|
|
|
this.metadataPrecedence = [...settings.metadataPrecedence]
|
|
|
|
} else {
|
|
|
|
// Added in v2.4.5
|
2023-11-12 14:30:23 +01:00
|
|
|
this.metadataPrecedence = ['folderStructure', 'audioMetatags', 'nfoFile', 'txtFiles', 'opfFile', 'absMetadata']
|
2023-10-09 00:10:43 +02:00
|
|
|
}
|
2024-01-05 07:45:35 +01:00
|
|
|
this.podcastSearchRegion = settings.podcastSearchRegion || 'us'
|
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,
|
2023-06-30 00:55:17 +02:00
|
|
|
audiobooksOnly: this.audiobooksOnly,
|
2024-05-26 23:01:08 +02:00
|
|
|
epubsAllowScriptedContent: this.epubsAllowScriptedContent,
|
2023-10-09 00:10:43 +02:00
|
|
|
hideSingleBookSeries: this.hideSingleBookSeries,
|
2024-03-12 17:04:26 +01:00
|
|
|
onlyShowLaterBooksInContinueSeries: this.onlyShowLaterBooksInContinueSeries,
|
2024-01-05 07:45:35 +01:00
|
|
|
metadataPrecedence: [...this.metadataPrecedence],
|
|
|
|
podcastSearchRegion: this.podcastSearchRegion
|
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) {
|
2023-10-09 00:10:43 +02:00
|
|
|
if (key === 'metadataPrecedence') {
|
|
|
|
if (payload[key] && Array.isArray(payload[key]) && payload[key].join() !== this[key].join()) {
|
|
|
|
this[key] = payload[key]
|
|
|
|
hasUpdates = true
|
|
|
|
}
|
|
|
|
} else if (this[key] !== payload[key]) {
|
2022-04-15 00:15:52 +02:00
|
|
|
this[key] = payload[key]
|
|
|
|
hasUpdates = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return hasUpdates
|
|
|
|
}
|
|
|
|
}
|
2024-05-26 23:01:08 +02:00
|
|
|
module.exports = LibrarySettings
|