mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-01-22 00:07:52 +01:00
Fix:Handle enabling/disabling library watchers #2775
This commit is contained in:
parent
a9c9c447f1
commit
c7cc994532
@ -103,15 +103,28 @@ class FolderWatcher extends EventEmitter {
|
|||||||
this.buildLibraryWatcher(library)
|
this.buildLibraryWatcher(library)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {import('./objects/Library')} library
|
||||||
|
*/
|
||||||
updateLibrary(library) {
|
updateLibrary(library) {
|
||||||
if (this.disabled || library.settings.disableWatcher) return
|
if (this.disabled) return
|
||||||
var libwatcher = this.libraryWatchers.find(lib => lib.id === library.id)
|
|
||||||
|
const libwatcher = this.libraryWatchers.find(lib => lib.id === library.id)
|
||||||
if (libwatcher) {
|
if (libwatcher) {
|
||||||
|
// Library watcher was disabled
|
||||||
|
if (library.settings.disableWatcher) {
|
||||||
|
Logger.info(`[Watcher] updateLibrary: Library "${library.name}" watcher disabled`)
|
||||||
|
libwatcher.watcher.close()
|
||||||
|
this.libraryWatchers = this.libraryWatchers.filter(lw => lw.id !== libwatcher.id)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
libwatcher.name = library.name
|
libwatcher.name = library.name
|
||||||
|
|
||||||
// If any folder paths were added or removed then re-init watcher
|
// If any folder paths were added or removed then re-init watcher
|
||||||
var pathsToAdd = library.folderPaths.filter(path => !libwatcher.paths.includes(path))
|
const pathsToAdd = library.folderPaths.filter(path => !libwatcher.paths.includes(path))
|
||||||
var pathsRemoved = libwatcher.paths.filter(path => !library.folderPaths.includes(path))
|
const pathsRemoved = libwatcher.paths.filter(path => !library.folderPaths.includes(path))
|
||||||
if (pathsToAdd.length || pathsRemoved.length) {
|
if (pathsToAdd.length || pathsRemoved.length) {
|
||||||
Logger.info(`[Watcher] Re-Initializing watcher for "${library.name}".`)
|
Logger.info(`[Watcher] Re-Initializing watcher for "${library.name}".`)
|
||||||
|
|
||||||
@ -119,6 +132,10 @@ class FolderWatcher extends EventEmitter {
|
|||||||
this.libraryWatchers = this.libraryWatchers.filter(lw => lw.id !== libwatcher.id)
|
this.libraryWatchers = this.libraryWatchers.filter(lw => lw.id !== libwatcher.id)
|
||||||
this.buildLibraryWatcher(library)
|
this.buildLibraryWatcher(library)
|
||||||
}
|
}
|
||||||
|
} else if (!library.settings.disableWatcher) {
|
||||||
|
// Library watcher was enabled
|
||||||
|
Logger.info(`[Watcher] updateLibrary: Library "${library.name}" watcher enabled - initializing`)
|
||||||
|
this.buildLibraryWatcher(library)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +128,14 @@ class LibraryController {
|
|||||||
res.json(libraryDownloadQueueDetails)
|
res.json(libraryDownloadQueueDetails)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PATCH: /api/libraries/:id
|
||||||
|
*
|
||||||
|
* @param {import('express').Request} req
|
||||||
|
* @param {import('express').Response} res
|
||||||
|
*/
|
||||||
async update(req, res) {
|
async update(req, res) {
|
||||||
|
/** @type {import('../objects/Library')} */
|
||||||
const library = req.library
|
const library = req.library
|
||||||
|
|
||||||
// Validate that the custom provider exists if given any
|
// Validate that the custom provider exists if given any
|
||||||
|
Loading…
Reference in New Issue
Block a user