MCPcopy
hub / github.com/advplyr/audiobookshelf / updateLibrary

Method updateLibrary

server/Watcher.js:129–160  ·  view source on GitHub ↗

* * @param {import('./models/Library')} library

(library)

Source from the content-addressed store, hash-verified

127 * @param {import('./models/Library')} library
128 */
129 updateLibrary(library) {
130 if (this.disabled) return
131
132 const libwatcher = this.libraryWatchers.find((lib) => lib.id === library.id)
133 if (libwatcher) {
134 // Library watcher was disabled
135 if (library.settings.disableWatcher) {
136 Logger.info(`[Watcher] updateLibrary: Library "${library.name}" watcher disabled`)
137 libwatcher.watcher.close()
138 this.libraryWatchers = this.libraryWatchers.filter((lw) => lw.id !== libwatcher.id)
139 return
140 }
141
142 libwatcher.name = library.name
143
144 // If any folder paths were added or removed then re-init watcher
145 const folderPaths = library.libraryFolders.map((f) => f.path)
146 const pathsToAdd = folderPaths.filter((path) => !libwatcher.paths.includes(path))
147 const pathsRemoved = libwatcher.paths.filter((path) => !folderPaths.includes(path))
148 if (pathsToAdd.length || pathsRemoved.length) {
149 Logger.info(`[Watcher] Re-Initializing watcher for "${library.name}".`)
150
151 libwatcher.watcher.close()
152 this.libraryWatchers = this.libraryWatchers.filter((lw) => lw.id !== libwatcher.id)
153 this.buildLibraryWatcher(library)
154 }
155 } else if (!library.settings.disableWatcher) {
156 // Library watcher was enabled
157 Logger.info(`[Watcher] updateLibrary: Library "${library.name}" watcher enabled - initializing`)
158 this.buildLibraryWatcher(library)
159 }
160 }
161
162 /**
163 *

Callers 1

updateMethod · 0.80

Calls 4

buildLibraryWatcherMethod · 0.95
findMethod · 0.80
infoMethod · 0.65
closeMethod · 0.45

Tested by

no test coverage detected