mirror of
				https://github.com/KevinMidboe/immich.git
				synced 2025-10-29 17:40:28 +00:00 
			
		
		
		
	refactor(server): move asset upload job to domain (#1434)
* refactor: move to domain * refactor: rename method * Update comments --------- Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
This commit is contained in:
		| @@ -1,50 +1,13 @@ | ||||
| import { AssetType } from '@app/infra'; | ||||
| import { | ||||
|   IAssetUploadedJob, | ||||
|   IMetadataExtractionJob, | ||||
|   IThumbnailGenerationJob, | ||||
|   IVideoTranscodeJob, | ||||
|   QueueName, | ||||
|   JobName, | ||||
| } from '@app/domain'; | ||||
| import { InjectQueue, Process, Processor } from '@nestjs/bull'; | ||||
| import { Job, Queue } from 'bull'; | ||||
| import { IAssetUploadedJob, JobName, JobService, QueueName } from '@app/domain'; | ||||
| import { Process, Processor } from '@nestjs/bull'; | ||||
| import { Job } from 'bull'; | ||||
|  | ||||
| @Processor(QueueName.ASSET_UPLOADED) | ||||
| export class AssetUploadedProcessor { | ||||
|   constructor( | ||||
|     @InjectQueue(QueueName.THUMBNAIL_GENERATION) | ||||
|     private thumbnailGeneratorQueue: Queue<IThumbnailGenerationJob>, | ||||
|   constructor(private jobService: JobService) {} | ||||
|  | ||||
|     @InjectQueue(QueueName.METADATA_EXTRACTION) | ||||
|     private metadataExtractionQueue: Queue<IMetadataExtractionJob>, | ||||
|  | ||||
|     @InjectQueue(QueueName.VIDEO_CONVERSION) | ||||
|     private videoConversionQueue: Queue<IVideoTranscodeJob>, | ||||
|   ) {} | ||||
|  | ||||
|   /** | ||||
|    * Post processing uploaded asset to perform the following function if missing | ||||
|    * 1. Generate JPEG Thumbnail | ||||
|    * 2. Generate Webp Thumbnail | ||||
|    * 3. EXIF extractor | ||||
|    * 4. Reverse Geocoding | ||||
|    * | ||||
|    * @param job asset-uploaded | ||||
|    */ | ||||
|   @Process(JobName.ASSET_UPLOADED) | ||||
|   async processUploadedVideo(job: Job<IAssetUploadedJob>) { | ||||
|     const { asset, fileName } = job.data; | ||||
|  | ||||
|     await this.thumbnailGeneratorQueue.add(JobName.GENERATE_JPEG_THUMBNAIL, { asset }); | ||||
|  | ||||
|     // Video Conversion | ||||
|     if (asset.type == AssetType.VIDEO) { | ||||
|       await this.videoConversionQueue.add(JobName.VIDEO_CONVERSION, { asset }); | ||||
|       await this.metadataExtractionQueue.add(JobName.EXTRACT_VIDEO_METADATA, { asset, fileName }); | ||||
|     } else { | ||||
|       // Extract Metadata/Exif for Images - Currently the EXIF library on the web cannot extract EXIF for video yet | ||||
|       await this.metadataExtractionQueue.add(JobName.EXIF_EXTRACTION, { asset, fileName }); | ||||
|     } | ||||
|     await this.jobService.handleUploadedAsset(job); | ||||
|   } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user