refactor: library watching (#7071)

This commit is contained in:
Jason Rasmussen
2024-02-13 08:48:47 -05:00
committed by GitHub
parent 3d7a7bcb7a
commit b648025e2f
9 changed files with 143 additions and 248 deletions

View File

@@ -2,10 +2,10 @@ import {
CrawlOptionsDto,
DiskUsage,
ImmichReadStream,
ImmichWatcher,
ImmichZipStream,
IStorageRepository,
mimeTypes,
WatchEvents,
} from '@app/domain';
import { ImmichLogger } from '@app/infra/logger';
import archiver from 'archiver';
@@ -136,8 +136,15 @@ export class FilesystemProvider implements IStorageRepository {
});
}
watch(paths: string[], options: WatchOptions): ImmichWatcher {
return chokidar.watch(paths, options);
watch(paths: string[], options: WatchOptions, events: Partial<WatchEvents>) {
const watcher = chokidar.watch(paths, options);
watcher.on('ready', () => events.onReady?.());
watcher.on('add', (path) => events.onAdd?.(path));
watcher.on('change', (path) => events.onChange?.(path));
watcher.on('unlink', (path) => events.onUnlink?.(path));
return () => watcher.close();
}
readdir = readdir;