2023-03-30 21:38:55 +02:00
|
|
|
import { AssetEntity, AssetType } from '@app/infra/entities';
|
2023-02-25 15:12:03 +01:00
|
|
|
import { Inject } from '@nestjs/common';
|
|
|
|
import { IAssetUploadedJob, IJobRepository, JobName } from '../job';
|
2023-03-03 03:47:08 +01:00
|
|
|
import { AssetCore } from './asset.core';
|
|
|
|
import { IAssetRepository } from './asset.repository';
|
2023-02-25 15:12:03 +01:00
|
|
|
|
|
|
|
export class AssetService {
|
2023-03-03 03:47:08 +01:00
|
|
|
private assetCore: AssetCore;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
@Inject(IAssetRepository) assetRepository: IAssetRepository,
|
|
|
|
@Inject(IJobRepository) private jobRepository: IJobRepository,
|
|
|
|
) {
|
2023-03-05 21:44:31 +01:00
|
|
|
this.assetCore = new AssetCore(assetRepository, jobRepository);
|
2023-03-03 03:47:08 +01:00
|
|
|
}
|
2023-02-25 15:12:03 +01:00
|
|
|
|
|
|
|
async handleAssetUpload(data: IAssetUploadedJob) {
|
|
|
|
await this.jobRepository.queue({ name: JobName.GENERATE_JPEG_THUMBNAIL, data });
|
|
|
|
|
|
|
|
if (data.asset.type == AssetType.VIDEO) {
|
|
|
|
await this.jobRepository.queue({ name: JobName.VIDEO_CONVERSION, data });
|
|
|
|
await this.jobRepository.queue({ name: JobName.EXTRACT_VIDEO_METADATA, data });
|
|
|
|
} else {
|
|
|
|
await this.jobRepository.queue({ name: JobName.EXIF_EXTRACTION, data });
|
|
|
|
}
|
|
|
|
}
|
2023-03-03 03:47:08 +01:00
|
|
|
|
|
|
|
save(asset: Partial<AssetEntity>) {
|
|
|
|
return this.assetCore.save(asset);
|
|
|
|
}
|
2023-02-25 15:12:03 +01:00
|
|
|
}
|