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';
|
2023-05-21 08:26:06 +02:00
|
|
|
import { AuthUserDto } from '../auth';
|
2023-05-22 17:26:56 +02:00
|
|
|
import { IAssetJob, IJobRepository, JobName } from '../job';
|
2023-03-03 03:47:08 +01:00
|
|
|
import { AssetCore } from './asset.core';
|
|
|
|
import { IAssetRepository } from './asset.repository';
|
2023-05-21 08:26:06 +02:00
|
|
|
import { MapMarkerDto } from './dto/map-marker.dto';
|
|
|
|
import { MapMarkerResponseDto } from './response-dto';
|
2023-02-25 15:12:03 +01:00
|
|
|
|
|
|
|
export class AssetService {
|
2023-03-03 03:47:08 +01:00
|
|
|
private assetCore: AssetCore;
|
|
|
|
|
|
|
|
constructor(
|
2023-05-21 08:26:06 +02:00
|
|
|
@Inject(IAssetRepository) private assetRepository: IAssetRepository,
|
2023-03-03 03:47:08 +01:00
|
|
|
@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
|
|
|
|
2023-05-22 17:26:56 +02:00
|
|
|
async handleAssetUpload(data: IAssetJob) {
|
2023-02-25 15:12:03 +01:00
|
|
|
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-05-21 08:26:06 +02:00
|
|
|
|
|
|
|
getMapMarkers(authUser: AuthUserDto, options: MapMarkerDto): Promise<MapMarkerResponseDto[]> {
|
|
|
|
return this.assetRepository.getMapMarkers(authUser.id, options);
|
|
|
|
}
|
2023-02-25 15:12:03 +01:00
|
|
|
}
|