mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-10-29 17:40:28 +00:00
* added transcode configs for nvenc,qsv and vaapi * updated dev docker compose * added software fallback * working vaapi * minor fixes and added tests * updated api * compile libvips * move hwaccel settings to `hwaccel.yml` * changed default dockerfile, moved `readdir` call * removed unused import * minor cleanup * fix for arm build * added documentation, minor fixes * added intel driver * updated docs styling * uppercase codec and api names * formatting * added tests * updated docs * removed semicolons * added link to `hwaccel.yml` * added newlines * added `hwaccel` section to docker-compose.prod.yml * ensure mesa drivers are installed * switch to mimalloc for sharp * moved build version and sha256 to json * let libmfx set the render device * possible fix for vp9 on qsv * updated tests * formatting * review suggestions * semicolon * moved `LD_PRELOAD` to start script * switched to jellyfin's ffmpeg package * fixed dockerfile * use cqp instead of icq for qsv vp9 * updated dockerfile * added sha256sum for other platforms * fixtures
98 lines
2.7 KiB
TypeScript
98 lines
2.7 KiB
TypeScript
import { DiskUsage, ImmichReadStream, ImmichZipStream, IStorageRepository } from '@app/domain';
|
|
import archiver from 'archiver';
|
|
import { constants, createReadStream, existsSync, mkdirSync } from 'fs';
|
|
import fs, { readdir } from 'fs/promises';
|
|
import mv from 'mv';
|
|
import { promisify } from 'node:util';
|
|
import path from 'path';
|
|
|
|
const moveFile = promisify<string, string, mv.Options>(mv);
|
|
|
|
export class FilesystemProvider implements IStorageRepository {
|
|
createZipStream(): ImmichZipStream {
|
|
const archive = archiver('zip', { store: true });
|
|
|
|
const addFile = (input: string, filename: string) => {
|
|
archive.file(input, { name: filename });
|
|
};
|
|
|
|
const finalize = () => archive.finalize();
|
|
|
|
return { stream: archive, addFile, finalize };
|
|
}
|
|
|
|
async createReadStream(filepath: string, mimeType?: string | null): Promise<ImmichReadStream> {
|
|
const { size } = await fs.stat(filepath);
|
|
await fs.access(filepath, constants.R_OK);
|
|
return {
|
|
stream: createReadStream(filepath),
|
|
length: size,
|
|
type: mimeType || undefined,
|
|
};
|
|
}
|
|
|
|
async moveFile(source: string, destination: string): Promise<void> {
|
|
if (await this.checkFileExists(destination)) {
|
|
throw new Error(`Destination file already exists: ${destination}`);
|
|
}
|
|
|
|
await moveFile(source, destination, { mkdirp: true, clobber: true });
|
|
}
|
|
|
|
async checkFileExists(filepath: string, mode = constants.F_OK): Promise<boolean> {
|
|
try {
|
|
await fs.access(filepath, mode);
|
|
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 });
|
|
}
|
|
}
|
|
|
|
async checkDiskUsage(folder: string): Promise<DiskUsage> {
|
|
const stats = await fs.statfs(folder);
|
|
return {
|
|
available: stats.bavail * stats.bsize,
|
|
free: stats.bfree * stats.bsize,
|
|
total: stats.blocks * stats.bsize,
|
|
};
|
|
}
|
|
|
|
readdir = readdir;
|
|
}
|