mirror of
https://github.com/samsonjs/immich.git
synced 2026-04-27 15:07:45 +00:00
* 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
49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import { MACHINE_LEARNING_ENABLED } from '@app/common';
|
|
import { Inject, Injectable, Logger } from '@nestjs/common';
|
|
import { IAssetJob } from '../job';
|
|
import { IMachineLearningRepository } from './machine-learning.interface';
|
|
import { ISmartInfoRepository } from './smart-info.repository';
|
|
|
|
@Injectable()
|
|
export class SmartInfoService {
|
|
private logger = new Logger(SmartInfoService.name);
|
|
|
|
constructor(
|
|
@Inject(ISmartInfoRepository) private repository: ISmartInfoRepository,
|
|
@Inject(IMachineLearningRepository) private machineLearning: IMachineLearningRepository,
|
|
) {}
|
|
|
|
async handleTagImage(data: IAssetJob) {
|
|
const { asset } = data;
|
|
|
|
if (!MACHINE_LEARNING_ENABLED || !asset.resizePath) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const tags = await this.machineLearning.tagImage({ thumbnailPath: asset.resizePath });
|
|
if (tags.length > 0) {
|
|
await this.repository.upsert({ assetId: asset.id, tags });
|
|
}
|
|
} catch (error: any) {
|
|
this.logger.error(`Unable to run image tagging pipeline: ${asset.id}`, error?.stack);
|
|
}
|
|
}
|
|
|
|
async handleDetectObjects(data: IAssetJob) {
|
|
const { asset } = data;
|
|
|
|
if (!MACHINE_LEARNING_ENABLED || !asset.resizePath) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const objects = await this.machineLearning.detectObjects({ thumbnailPath: asset.resizePath });
|
|
if (objects.length > 0) {
|
|
await this.repository.upsert({ assetId: asset.id, objects });
|
|
}
|
|
} catch (error: any) {
|
|
this.logger.error(`Unable run object detection pipeline: ${asset.id}`, error?.stack);
|
|
}
|
|
}
|
|
}
|