1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-10 13:56:47 +01:00
immich/server/src/services/storage.service.ts
AmAn Sharma 6e6deec40c
feat: use ILoggerRepository (#8855)
* Migrate ImmichLogger over to injected ILoggerRepository

* chore: cleanup and tests

---------

Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
2024-04-16 17:30:31 -04:00

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;
}
}