4cb0f37918
* move watcher init to micro
* document watcher recovery
* chore: fix lint
* add try lock
* use global library watch lock
* fix: ensure lock stays on
* fix: mocks
* unit test for library watch lock
* move statement to correct test
* fix: correct return type of try lock
* fix: tests
* add library teardown
* add chokidar error handler
* make event strings an enum
* wait for event refactor
* refactor event type mocks
* expect correct error
* don't release lock in teardown
* chore: lint
* use enum
* fix mock
* fix lint
* fix watcher await
* remove await
* simplify typing
* remove async
* Revert "remove async"
This reverts commit 84ab5abac4.
* can now change watch settings at runtime
* fix lint
* only watch libraries if enabled
---------
Co-authored-by: mertalev <101130780+mertalev@users.noreply.github.com>
Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
61 lines
2.0 KiB
TypeScript
61 lines
2.0 KiB
TypeScript
import { WatchOptions } from 'chokidar';
|
|
import { Stats } from 'node:fs';
|
|
import { FileReadOptions } from 'node:fs/promises';
|
|
import { Readable } from 'node:stream';
|
|
import { CrawlOptionsDto } from '../library';
|
|
|
|
export interface ImmichReadStream {
|
|
stream: Readable;
|
|
type?: string;
|
|
length?: number;
|
|
}
|
|
|
|
export interface ImmichZipStream extends ImmichReadStream {
|
|
addFile: (inputPath: string, filename: string) => void;
|
|
finalize: () => Promise<void>;
|
|
}
|
|
|
|
export interface DiskUsage {
|
|
available: number;
|
|
free: number;
|
|
total: number;
|
|
}
|
|
|
|
export const IStorageRepository = 'IStorageRepository';
|
|
|
|
export interface WatchEvents {
|
|
onReady(): void;
|
|
onAdd(path: string): void;
|
|
onChange(path: string): void;
|
|
onUnlink(path: string): void;
|
|
onError(error: Error): void;
|
|
}
|
|
|
|
export enum StorageEventType {
|
|
READY = 'ready',
|
|
ADD = 'add',
|
|
CHANGE = 'change',
|
|
UNLINK = 'unlink',
|
|
ERROR = 'error',
|
|
}
|
|
|
|
export interface IStorageRepository {
|
|
createZipStream(): ImmichZipStream;
|
|
createReadStream(filepath: string, mimeType?: string | null): Promise<ImmichReadStream>;
|
|
readFile(filepath: string, options?: FileReadOptions<Buffer>): Promise<Buffer>;
|
|
writeFile(filepath: string, buffer: Buffer): Promise<void>;
|
|
unlink(filepath: string): Promise<void>;
|
|
unlinkDir(folder: string, options?: { recursive?: boolean; force?: boolean }): Promise<void>;
|
|
removeEmptyDirs(folder: string, self?: boolean): Promise<void>;
|
|
checkFileExists(filepath: string, mode?: number): Promise<boolean>;
|
|
mkdirSync(filepath: string): void;
|
|
checkDiskUsage(folder: string): Promise<DiskUsage>;
|
|
readdir(folder: string): Promise<string[]>;
|
|
stat(filepath: string): Promise<Stats>;
|
|
crawl(crawlOptions: CrawlOptionsDto): Promise<string[]>;
|
|
copyFile(source: string, target: string): Promise<void>;
|
|
rename(source: string, target: string): Promise<void>;
|
|
watch(paths: string[], options: WatchOptions, events: Partial<WatchEvents>): () => Promise<void>;
|
|
utimes(filepath: string, atime: Date, mtime: Date): Promise<void>;
|
|
}
|