From 663ab2db90d11998b9365f4df9c6c4b296462a4b Mon Sep 17 00:00:00 2001 From: advplyr Date: Thu, 3 Feb 2022 16:39:05 -0600 Subject: [PATCH] Fix:Save library updating name only #350 --- server/controllers/LibraryController.js | 4 +++- server/objects/Library.js | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/server/controllers/LibraryController.js b/server/controllers/LibraryController.js index edcf4af3..baf9c1bb 100644 --- a/server/controllers/LibraryController.js +++ b/server/controllers/LibraryController.js @@ -51,13 +51,15 @@ class LibraryController { async update(req, res) { var library = req.library + var hasUpdates = library.update(req.body) + // TODO: Should check if this is an update to folder paths or name only if (hasUpdates) { // Update watcher this.watcher.updateLibrary(library) // Remove audiobooks no longer in library - var audiobooksToRemove = this.db.audiobooks.filter(ab => !library.checkFullPathInLibrary(ab.fullPath)) + var audiobooksToRemove = this.db.audiobooks.filter(ab => ab.libraryId === library.id && !library.checkFullPathInLibrary(ab.fullPath)) if (audiobooksToRemove.length) { Logger.info(`[Scanner] Updating library, removing ${audiobooksToRemove.length} audiobooks`) for (let i = 0; i < audiobooksToRemove.length; i++) { diff --git a/server/objects/Library.js b/server/objects/Library.js index d89ba156..046e7378 100644 --- a/server/objects/Library.js +++ b/server/objects/Library.js @@ -97,7 +97,9 @@ class Library { }) } - hasUpdates = newFolders.length || removedFolders.length + if (newFolders.length || removedFolders.length) { + hasUpdates = true + } } if (hasUpdates) { this.lastUpdate = Date.now() @@ -106,7 +108,8 @@ class Library { } checkFullPathInLibrary(fullPath) { - return this.folders.find(folder => fullPath.startsWith(folder.fullPath)) + fullPath = fullPath.replace(/\\/g, '/') + return this.folders.find(folder => fullPath.startsWith(folder.fullPath.replace(/\\/g, '/'))) } getFolderById(id) {