2023-03-30 15:38:55 -04:00
|
|
|
import { AssetEntity, AssetType } from '@app/infra/entities';
|
2023-02-25 09:12:03 -05:00
|
|
|
import { Inject } from '@nestjs/common';
|
|
|
|
|
import { IAssetUploadedJob, IJobRepository, JobName } from '../job';
|
2023-03-02 21:47:08 -05:00
|
|
|
import { AssetCore } from './asset.core';
|
|
|
|
|
import { IAssetRepository } from './asset.repository';
|
2023-02-25 09:12:03 -05:00
|
|
|
|
|
|
|
|
export class AssetService {
|
2023-03-02 21:47:08 -05:00
|
|
|
private assetCore: AssetCore;
|
|
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
|
@Inject(IAssetRepository) assetRepository: IAssetRepository,
|
|
|
|
|
@Inject(IJobRepository) private jobRepository: IJobRepository,
|
|
|
|
|
) {
|
2023-03-05 15:44:31 -05:00
|
|
|
this.assetCore = new AssetCore(assetRepository, jobRepository);
|
2023-03-02 21:47:08 -05:00
|
|
|
}
|
2023-02-25 09:12:03 -05: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-02 21:47:08 -05:00
|
|
|
|
|
|
|
|
save(asset: Partial<AssetEntity>) {
|
|
|
|
|
return this.assetCore.save(asset);
|
|
|
|
|
}
|
2023-02-25 09:12:03 -05:00
|
|
|
}
|