mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
refactor(server): jobs and processors (#1787)
* refactor: jobs and processors * refactor: storage migration processor * fix: tests * fix: code warning * chore: ignore coverage from infra * fix: sync move asset logic between job core and asset core * refactor: move error handling inside of catch * refactor(server): job core into dedicated service calls * refactor: smart info * fix: tests * chore: smart info tests * refactor: use asset repository * refactor: thumbnail processor * chore: coverage reqs
This commit is contained in:
parent
71d8567f18
commit
6c7679714b
108 changed files with 1645 additions and 1072 deletions
|
|
@ -1,13 +1,15 @@
|
|||
import { ImmichReadStream, IStorageRepository } from '@app/domain';
|
||||
import { constants, createReadStream, stat } from 'fs';
|
||||
import { constants, createReadStream, existsSync, mkdirSync } from 'fs';
|
||||
import fs from 'fs/promises';
|
||||
import { promisify } from 'util';
|
||||
import mv from 'mv';
|
||||
import { promisify } from 'node:util';
|
||||
import path from 'path';
|
||||
|
||||
const fileInfo = promisify(stat);
|
||||
const moveFile = promisify<string, string, mv.Options>(mv);
|
||||
|
||||
export class FilesystemProvider implements IStorageRepository {
|
||||
async createReadStream(filepath: string, mimeType: string): Promise<ImmichReadStream> {
|
||||
const { size } = await fileInfo(filepath);
|
||||
const { size } = await fs.stat(filepath);
|
||||
await fs.access(filepath, constants.R_OK | constants.W_OK);
|
||||
return {
|
||||
stream: createReadStream(filepath),
|
||||
|
|
@ -15,4 +17,53 @@ export class FilesystemProvider implements IStorageRepository {
|
|||
type: mimeType,
|
||||
};
|
||||
}
|
||||
|
||||
async moveFile(source: string, destination: string): Promise<void> {
|
||||
await moveFile(source, destination, { mkdirp: true, clobber: false });
|
||||
}
|
||||
|
||||
async checkFileExists(filepath: string): Promise<boolean> {
|
||||
try {
|
||||
await fs.access(filepath, constants.F_OK);
|
||||
return true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async unlink(file: string) {
|
||||
await fs.unlink(file);
|
||||
}
|
||||
|
||||
async unlinkDir(folder: string, options: { recursive?: boolean; force?: boolean }) {
|
||||
await fs.rm(folder, options);
|
||||
}
|
||||
|
||||
async removeEmptyDirs(directory: string) {
|
||||
this._removeEmptyDirs(directory, false);
|
||||
}
|
||||
|
||||
private async _removeEmptyDirs(directory: string, self: boolean) {
|
||||
// lstat does not follow symlinks (in contrast to stat)
|
||||
const stats = await fs.lstat(directory);
|
||||
if (!stats.isDirectory()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const files = await fs.readdir(directory);
|
||||
await Promise.all(files.map((file) => this._removeEmptyDirs(path.join(directory, file), true)));
|
||||
|
||||
if (self) {
|
||||
const updated = await fs.readdir(directory);
|
||||
if (updated.length === 0) {
|
||||
await fs.rmdir(directory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mkdirSync(filepath: string): void {
|
||||
if (!existsSync(filepath)) {
|
||||
mkdirSync(filepath, { recursive: true });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue