mirror of
https://github.com/immich-app/immich.git
synced 2025-01-10 13:56:47 +01:00
6e6deec40c
* Migrate ImmichLogger over to injected ILoggerRepository * chore: cleanup and tests --------- Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { Inject, Injectable } from '@nestjs/common';
|
|
import { StorageCore, StorageFolder } from 'src/cores/storage.core';
|
|
import { IDeleteFilesJob, JobStatus } from 'src/interfaces/job.interface';
|
|
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
|
import { IStorageRepository } from 'src/interfaces/storage.interface';
|
|
|
|
@Injectable()
|
|
export class StorageService {
|
|
constructor(
|
|
@Inject(IStorageRepository) private storageRepository: IStorageRepository,
|
|
@Inject(ILoggerRepository) private logger: ILoggerRepository,
|
|
) {
|
|
this.logger.setContext(StorageService.name);
|
|
}
|
|
|
|
init() {
|
|
const libraryBase = StorageCore.getBaseFolder(StorageFolder.LIBRARY);
|
|
this.storageRepository.mkdirSync(libraryBase);
|
|
}
|
|
|
|
async handleDeleteFiles(job: IDeleteFilesJob) {
|
|
const { files } = job;
|
|
|
|
// TODO: one job per file
|
|
for (const file of files) {
|
|
if (!file) {
|
|
continue;
|
|
}
|
|
|
|
try {
|
|
await this.storageRepository.unlink(file);
|
|
} catch (error: any) {
|
|
this.logger.warn('Unable to remove file from disk', error);
|
|
}
|
|
}
|
|
|
|
return JobStatus.SUCCESS;
|
|
}
|
|
}
|