Skip to content

Commit

Permalink
Fix:Handle enabling/disabling library watchers #2775
Browse files Browse the repository at this point in the history
  • Loading branch information
advplyr committed Mar 31, 2024
1 parent a9c9c44 commit c7cc994
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
25 changes: 21 additions & 4 deletions server/Watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,39 @@ class FolderWatcher extends EventEmitter {
this.buildLibraryWatcher(library)
}

/**
*
* @param {import('./objects/Library')} library
*/
updateLibrary(library) {
if (this.disabled || library.settings.disableWatcher) return
var libwatcher = this.libraryWatchers.find(lib => lib.id === library.id)
if (this.disabled) return

const libwatcher = this.libraryWatchers.find(lib => lib.id === library.id)
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

// If any folder paths were added or removed then re-init watcher
var pathsToAdd = library.folderPaths.filter(path => !libwatcher.paths.includes(path))
var pathsRemoved = libwatcher.paths.filter(path => !library.folderPaths.includes(path))
const pathsToAdd = library.folderPaths.filter(path => !libwatcher.paths.includes(path))
const pathsRemoved = libwatcher.paths.filter(path => !library.folderPaths.includes(path))
if (pathsToAdd.length || pathsRemoved.length) {
Logger.info(`[Watcher] Re-Initializing watcher for "${library.name}".`)

libwatcher.watcher.close()
this.libraryWatchers = this.libraryWatchers.filter(lw => lw.id !== libwatcher.id)
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)
}
}

Expand Down
7 changes: 7 additions & 0 deletions server/controllers/LibraryController.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,14 @@ class LibraryController {
res.json(libraryDownloadQueueDetails)
}

/**
* PATCH: /api/libraries/:id
*
* @param {import('express').Request} req
* @param {import('express').Response} res
*/
async update(req, res) {
/** @type {import('../objects/Library')} */
const library = req.library

// Validate that the custom provider exists if given any
Expand Down

0 comments on commit c7cc994

Please sign in to comment.