mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
feat(server/web) Add manual job trigger mechanism to the web (#767)
This commit is contained in:
parent
854c214bc0
commit
7587f858ae
75 changed files with 3052 additions and 238 deletions
|
|
@ -1,23 +1,19 @@
|
|||
import { ImmichLogLevel } from '@app/common/constants/log-level.constant';
|
||||
import { AssetEntity } from '@app/database/entities/asset.entity';
|
||||
import { ExifEntity } from '@app/database/entities/exif.entity';
|
||||
import { SmartInfoEntity } from '@app/database/entities/smart-info.entity';
|
||||
import {
|
||||
IExifExtractionProcessor,
|
||||
IVideoLengthExtractionProcessor,
|
||||
exifExtractionProcessorName,
|
||||
imageTaggingProcessorName,
|
||||
objectDetectionProcessorName,
|
||||
videoMetadataExtractionProcessorName,
|
||||
metadataExtractionQueueName,
|
||||
reverseGeocodingProcessorName,
|
||||
IReverseGeocodingProcessor,
|
||||
QueueNameEnum,
|
||||
} from '@app/job';
|
||||
import { Process, Processor } from '@nestjs/bull';
|
||||
import { Logger } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import axios from 'axios';
|
||||
import { Job } from 'bull';
|
||||
import exifr from 'exifr';
|
||||
import ffmpeg from 'fluent-ffmpeg';
|
||||
|
|
@ -79,7 +75,7 @@ export interface GeoData {
|
|||
distance: number;
|
||||
}
|
||||
|
||||
@Processor(metadataExtractionQueueName)
|
||||
@Processor(QueueNameEnum.METADATA_EXTRACTION)
|
||||
export class MetadataExtractionProcessor {
|
||||
private isGeocodeInitialized = false;
|
||||
private logLevel: ImmichLogLevel;
|
||||
|
|
@ -91,9 +87,6 @@ export class MetadataExtractionProcessor {
|
|||
@InjectRepository(ExifEntity)
|
||||
private exifRepository: Repository<ExifEntity>,
|
||||
|
||||
@InjectRepository(SmartInfoEntity)
|
||||
private smartInfoRepository: Repository<SmartInfoEntity>,
|
||||
|
||||
private configService: ConfigService,
|
||||
) {
|
||||
if (!configService.get('DISABLE_REVERSE_GEOCODING')) {
|
||||
|
|
@ -109,7 +102,8 @@ export class MetadataExtractionProcessor {
|
|||
alternateNames: false,
|
||||
},
|
||||
countries: [],
|
||||
dumpDirectory: configService.get('REVERSE_GEOCODING_DUMP_DIRECTORY') || (process.cwd() + '/.reverse-geocoding-dump/'),
|
||||
dumpDirectory:
|
||||
configService.get('REVERSE_GEOCODING_DUMP_DIRECTORY') || process.cwd() + '/.reverse-geocoding-dump/',
|
||||
}).then(() => {
|
||||
this.isGeocodeInitialized = true;
|
||||
Logger.log('Reverse Geocoding Initialised');
|
||||
|
|
@ -273,48 +267,6 @@ export class MetadataExtractionProcessor {
|
|||
}
|
||||
}
|
||||
|
||||
@Process({ name: imageTaggingProcessorName, concurrency: 2 })
|
||||
async tagImage(job: Job) {
|
||||
const { asset }: { asset: AssetEntity } = job.data;
|
||||
|
||||
const res = await axios.post('http://immich-machine-learning:3003/image-classifier/tag-image', {
|
||||
thumbnailPath: asset.resizePath,
|
||||
});
|
||||
|
||||
if (res.status == 201 && res.data.length > 0) {
|
||||
const smartInfo = new SmartInfoEntity();
|
||||
smartInfo.assetId = asset.id;
|
||||
smartInfo.tags = [...res.data];
|
||||
|
||||
await this.smartInfoRepository.upsert(smartInfo, {
|
||||
conflictPaths: ['assetId'],
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Process({ name: objectDetectionProcessorName, concurrency: 2 })
|
||||
async detectObject(job: Job) {
|
||||
try {
|
||||
const { asset }: { asset: AssetEntity } = job.data;
|
||||
|
||||
const res = await axios.post('http://immich-machine-learning:3003/object-detection/detect-object', {
|
||||
thumbnailPath: asset.resizePath,
|
||||
});
|
||||
|
||||
if (res.status == 201 && res.data.length > 0) {
|
||||
const smartInfo = new SmartInfoEntity();
|
||||
smartInfo.assetId = asset.id;
|
||||
smartInfo.objects = [...res.data];
|
||||
|
||||
await this.smartInfoRepository.upsert(smartInfo, {
|
||||
conflictPaths: ['assetId'],
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
Logger.error(`Failed to trigger object detection pipe line ${String(error)}`);
|
||||
}
|
||||
}
|
||||
|
||||
@Process({ name: videoMetadataExtractionProcessorName, concurrency: 2 })
|
||||
async extractVideoMetadata(job: Job<IVideoLengthExtractionProcessor>) {
|
||||
const { asset, fileName } = job.data;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue