mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-08 00:08:14 +01:00
Fix:Scanner detecting library item folder renames #1161
This commit is contained in:
parent
cdd740015c
commit
c264332994
@ -21,9 +21,10 @@ class LibraryItemScanner {
|
|||||||
* Scan single library item
|
* Scan single library item
|
||||||
*
|
*
|
||||||
* @param {string} libraryItemId
|
* @param {string} libraryItemId
|
||||||
|
* @param {{relPath:string, path:string}} [renamedPaths] used by watcher when item folder was renamed
|
||||||
* @returns {number} ScanResult
|
* @returns {number} ScanResult
|
||||||
*/
|
*/
|
||||||
async scanLibraryItem(libraryItemId) {
|
async scanLibraryItem(libraryItemId, renamedPaths = null) {
|
||||||
// TODO: Add task manager
|
// TODO: Add task manager
|
||||||
const libraryItem = await Database.libraryItemModel.findByPk(libraryItemId)
|
const libraryItem = await Database.libraryItemModel.findByPk(libraryItemId)
|
||||||
if (!libraryItem) {
|
if (!libraryItem) {
|
||||||
@ -50,9 +51,9 @@ class LibraryItemScanner {
|
|||||||
|
|
||||||
const scanLogger = new ScanLogger()
|
const scanLogger = new ScanLogger()
|
||||||
scanLogger.verbose = true
|
scanLogger.verbose = true
|
||||||
scanLogger.setData('libraryItem', libraryItem.relPath)
|
scanLogger.setData('libraryItem', renamedPaths?.relPath || libraryItem.relPath)
|
||||||
|
|
||||||
const libraryItemPath = fileUtils.filePathToPOSIX(libraryItem.path)
|
const libraryItemPath = renamedPaths?.path || fileUtils.filePathToPOSIX(libraryItem.path)
|
||||||
const folder = library.libraryFolders[0]
|
const folder = library.libraryFolders[0]
|
||||||
const libraryItemScanData = await this.getLibraryItemScanData(libraryItemPath, library, folder, false)
|
const libraryItemScanData = await this.getLibraryItemScanData(libraryItemPath, library, folder, false)
|
||||||
|
|
||||||
|
@ -483,6 +483,7 @@ class LibraryScanner {
|
|||||||
path: potentialChildDirs
|
path: potentialChildDirs
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let renamedPaths = {}
|
||||||
if (!existingLibraryItem) {
|
if (!existingLibraryItem) {
|
||||||
const dirIno = await fileUtils.getIno(fullPath)
|
const dirIno = await fileUtils.getIno(fullPath)
|
||||||
existingLibraryItem = await Database.libraryItemModel.findOneOld({
|
existingLibraryItem = await Database.libraryItemModel.findOneOld({
|
||||||
@ -493,6 +494,8 @@ class LibraryScanner {
|
|||||||
// Update library item paths for scan
|
// Update library item paths for scan
|
||||||
existingLibraryItem.path = fullPath
|
existingLibraryItem.path = fullPath
|
||||||
existingLibraryItem.relPath = itemDir
|
existingLibraryItem.relPath = itemDir
|
||||||
|
renamedPaths.path = fullPath
|
||||||
|
renamedPaths.relPath = itemDir
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (existingLibraryItem) {
|
if (existingLibraryItem) {
|
||||||
@ -512,7 +515,7 @@ class LibraryScanner {
|
|||||||
|
|
||||||
// Scan library item for updates
|
// Scan library item for updates
|
||||||
Logger.debug(`[LibraryScanner] Folder update for relative path "${itemDir}" is in library item "${existingLibraryItem.media.metadata.title}" - scan for updates`)
|
Logger.debug(`[LibraryScanner] Folder update for relative path "${itemDir}" is in library item "${existingLibraryItem.media.metadata.title}" - scan for updates`)
|
||||||
itemGroupingResults[itemDir] = await LibraryItemScanner.scanLibraryItem(existingLibraryItem.id)
|
itemGroupingResults[itemDir] = await LibraryItemScanner.scanLibraryItem(existingLibraryItem.id, renamedPaths)
|
||||||
continue
|
continue
|
||||||
} else if (library.settings.audiobooksOnly && !fileUpdateGroup[itemDir].some?.(scanUtils.checkFilepathIsAudioFile)) {
|
} else if (library.settings.audiobooksOnly && !fileUpdateGroup[itemDir].some?.(scanUtils.checkFilepathIsAudioFile)) {
|
||||||
Logger.debug(`[LibraryScanner] Folder update for relative path "${itemDir}" has no audio files`)
|
Logger.debug(`[LibraryScanner] Folder update for relative path "${itemDir}" has no audio files`)
|
||||||
|
Loading…
Reference in New Issue
Block a user