refactor(server): Move metadata extraction to domain (#4243)

* use storageRepository in metadata extraction

* move metadata extraction processor to domain

* cleanup infra/domain

---------

Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
This commit is contained in:
Daniel Dietzler
2023-09-27 20:44:51 +02:00
committed by GitHub
parent 9bada51d56
commit 3a44e8f8d3
17 changed files with 410 additions and 396 deletions

View File

@@ -8,7 +8,7 @@ import {
} from '@app/domain';
import archiver from 'archiver';
import { constants, createReadStream, existsSync, mkdirSync } from 'fs';
import fs, { readdir } from 'fs/promises';
import fs, { readdir, writeFile } from 'fs/promises';
import { glob } from 'glob';
import mv from 'mv';
import { promisify } from 'node:util';
@@ -39,6 +39,18 @@ export class FilesystemProvider implements IStorageRepository {
};
}
async readFile(filepath: string, options?: fs.FileReadOptions<Buffer>): Promise<Buffer> {
const file = await fs.open(filepath);
try {
const { buffer } = await file.read(options);
return buffer;
} finally {
await file.close();
}
}
writeFile = writeFile;
async moveFile(source: string, destination: string): Promise<void> {
if (await this.checkFileExists(destination)) {
throw new Error(`Destination file already exists: ${destination}`);