mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-12-10 05:49:37 +00:00
Updates to use new Library model
This commit is contained in:
parent
8774e6be71
commit
38edcdca4b
6 changed files with 114 additions and 57 deletions
|
|
@ -45,6 +45,10 @@ class FolderWatcher extends EventEmitter {
|
|||
return this.pendingFileUpdates.map((f) => f.path)
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {import('./models/Library')} library
|
||||
*/
|
||||
buildLibraryWatcher(library) {
|
||||
if (this.libraryWatchers.find((w) => w.id === library.id)) {
|
||||
Logger.warn('[Watcher] Already watching library', library.name)
|
||||
|
|
@ -52,7 +56,7 @@ class FolderWatcher extends EventEmitter {
|
|||
}
|
||||
Logger.info(`[Watcher] Initializing watcher for "${library.name}".`)
|
||||
|
||||
const folderPaths = library.folderPaths
|
||||
const folderPaths = library.libraryFolders.map((f) => f.path)
|
||||
folderPaths.forEach((fp) => {
|
||||
Logger.debug(`[Watcher] Init watcher for library folder path "${fp}"`)
|
||||
})
|
||||
|
|
@ -90,12 +94,16 @@ class FolderWatcher extends EventEmitter {
|
|||
this.libraryWatchers.push({
|
||||
id: library.id,
|
||||
name: library.name,
|
||||
folders: library.folders,
|
||||
paths: library.folderPaths,
|
||||
libraryFolders: library.libraryFolders,
|
||||
paths: folderPaths,
|
||||
watcher
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {import('./models/Library')[]} libraries
|
||||
*/
|
||||
initWatcher(libraries) {
|
||||
libraries.forEach((lib) => {
|
||||
if (!lib.settings.disableWatcher) {
|
||||
|
|
@ -104,12 +112,17 @@ class FolderWatcher extends EventEmitter {
|
|||
})
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {import('./models/Library')} library
|
||||
*/
|
||||
addLibrary(library) {
|
||||
if (this.disabled || library.settings.disableWatcher) return
|
||||
this.buildLibraryWatcher(library)
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Update to new library model
|
||||
*
|
||||
* @param {import('./objects/Library')} library
|
||||
*/
|
||||
|
|
@ -129,8 +142,9 @@ class FolderWatcher extends EventEmitter {
|
|||
libwatcher.name = library.name
|
||||
|
||||
// If any folder paths were added or removed then re-init watcher
|
||||
const pathsToAdd = library.folderPaths.filter((path) => !libwatcher.paths.includes(path))
|
||||
const pathsRemoved = libwatcher.paths.filter((path) => !library.folderPaths.includes(path))
|
||||
const folderPaths = library.libraryFolders.map((f) => f.path)
|
||||
const pathsToAdd = folderPaths.filter((path) => !libwatcher.paths.includes(path))
|
||||
const pathsRemoved = libwatcher.paths.filter((path) => !folderPaths.includes(path))
|
||||
if (pathsToAdd.length || pathsRemoved.length) {
|
||||
Logger.info(`[Watcher] Re-Initializing watcher for "${library.name}".`)
|
||||
|
||||
|
|
@ -145,6 +159,10 @@ class FolderWatcher extends EventEmitter {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {import('./models/Library')} library
|
||||
*/
|
||||
removeLibrary(library) {
|
||||
if (this.disabled) return
|
||||
var libwatcher = this.libraryWatchers.find((lib) => lib.id === library.id)
|
||||
|
|
@ -255,15 +273,15 @@ class FolderWatcher extends EventEmitter {
|
|||
}
|
||||
|
||||
// Get file folder
|
||||
const folder = libwatcher.folders.find((fold) => isSameOrSubPath(fold.fullPath, path))
|
||||
const folder = libwatcher.libraryFolders.find((fold) => isSameOrSubPath(fold.path, path))
|
||||
if (!folder) {
|
||||
Logger.error(`[Watcher] New file folder not found in library "${libwatcher.name}" with path "${path}"`)
|
||||
return
|
||||
}
|
||||
|
||||
const folderFullPath = filePathToPOSIX(folder.fullPath)
|
||||
const folderPath = filePathToPOSIX(folder.path)
|
||||
|
||||
const relPath = path.replace(folderFullPath, '')
|
||||
const relPath = path.replace(folderPath, '')
|
||||
|
||||
if (Path.extname(relPath).toLowerCase() === '.part') {
|
||||
Logger.debug(`[Watcher] Ignoring .part file "${relPath}"`)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue