From 22ad16e11b427ff6301a781025cea96cf98b8ce3 Mon Sep 17 00:00:00 2001 From: advplyr Date: Tue, 17 Sep 2024 16:10:32 -0500 Subject: [PATCH] Fix:Server crash on scan for library with no metadataPrecedence set #3434 --- server/models/Library.js | 6 +++++- server/scanner/BookScanner.js | 2 +- server/scanner/LibraryScanner.js | 7 ++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/server/models/Library.js b/server/models/Library.js index 972aa264..90dd2512 100644 --- a/server/models/Library.js +++ b/server/models/Library.js @@ -70,11 +70,15 @@ class Library extends Model { epubsAllowScriptedContent: false, hideSingleBookSeries: false, onlyShowLaterBooksInContinueSeries: false, - metadataPrecedence: ['folderStructure', 'audioMetatags', 'nfoFile', 'txtFiles', 'opfFile', 'absMetadata'] + metadataPrecedence: this.defaultMetadataPrecedence } } } + static get defaultMetadataPrecedence() { + return ['folderStructure', 'audioMetatags', 'nfoFile', 'txtFiles', 'opfFile', 'absMetadata'] + } + /** * * @returns {Promise} diff --git a/server/scanner/BookScanner.js b/server/scanner/BookScanner.js index 07f817a8..279fcf64 100644 --- a/server/scanner/BookScanner.js +++ b/server/scanner/BookScanner.js @@ -655,7 +655,7 @@ class BookScanner { } const bookMetadataSourceHandler = new BookScanner.BookMetadataSourceHandler(bookMetadata, audioFiles, ebookFileScanData, libraryItemData, libraryScan, existingLibraryItemId) - const metadataPrecedence = librarySettings.metadataPrecedence || ['folderStructure', 'audioMetatags', 'nfoFile', 'txtFiles', 'opfFile', 'absMetadata'] + const metadataPrecedence = librarySettings.metadataPrecedence || Database.libraryModel.defaultMetadataPrecedence libraryScan.addLog(LogLevel.DEBUG, `"${bookMetadata.title}" Getting metadata with precedence [${metadataPrecedence.join(', ')}]`) for (const metadataSource of metadataPrecedence) { if (bookMetadataSourceHandler[metadataSource]) { diff --git a/server/scanner/LibraryScanner.js b/server/scanner/LibraryScanner.js index 76022415..5cd8b5c6 100644 --- a/server/scanner/LibraryScanner.js +++ b/server/scanner/LibraryScanner.js @@ -59,9 +59,10 @@ class LibraryScanner { return } - if (library.isBook && library.settings.metadataPrecedence.join() !== library.lastScanMetadataPrecedence.join()) { + const metadataPrecedence = library.settings.metadataPrecedence || Database.libraryModel.defaultMetadataPrecedence + if (library.isBook && metadataPrecedence.join() !== library.lastScanMetadataPrecedence.join()) { const lastScanMetadataPrecedence = library.lastScanMetadataPrecedence?.join() || 'Unset' - Logger.info(`[LibraryScanner] Library metadata precedence changed since last scan. From [${lastScanMetadataPrecedence}] to [${library.settings.metadataPrecedence.join()}]`) + Logger.info(`[LibraryScanner] Library metadata precedence changed since last scan. From [${lastScanMetadataPrecedence}] to [${metadataPrecedence.join()}]`) forceRescan = true } @@ -90,7 +91,7 @@ class LibraryScanner { library.lastScanVersion = packageJson.version if (library.isBook) { const newExtraData = library.extraData || {} - newExtraData.lastScanMetadataPrecedence = library.settings.metadataPrecedence + newExtraData.lastScanMetadataPrecedence = metadataPrecedence library.extraData = newExtraData library.changed('extraData', true) }