diff --git a/backend/src/bundles/templates/templates.service.ts b/backend/src/bundles/templates/templates.service.ts index a63087dbc..bf97c4e1b 100644 --- a/backend/src/bundles/templates/templates.service.ts +++ b/backend/src/bundles/templates/templates.service.ts @@ -1,7 +1,11 @@ import { HTTPCode, HttpError } from '~/common/http/http.js'; +import { type ImageService } from '~/common/services/image/image.service.js'; import { type Service } from '~/common/types/types.js'; -import { type UpdateVideoRequestDto } from '../videos/types/types.js'; +import { + type Scene, + type UpdateVideoRequestDto, +} from '../videos/types/types.js'; import { templateErrorMessage } from './enums/enums.js'; import { TemplateEntity } from './templates.entity.js'; import { type TemplateRepository } from './templates.repository.js'; @@ -14,9 +18,14 @@ import { class TemplateService implements Service { private templateRepository: TemplateRepository; + private imageService: ImageService; - public constructor(templateRepository: TemplateRepository) { + public constructor( + templateRepository: TemplateRepository, + imageService: ImageService, + ) { this.templateRepository = templateRepository; + this.imageService = imageService; } public async findById(id: string): Promise { @@ -54,7 +63,9 @@ class TemplateService implements Service { const { composition, name, userId } = payload; // TODO: CREATE PREVIEW - const compositionPreviewUrl = composition.scenes[0]?.avatar?.url ?? ''; + const compositionPreviewUrl = await this.imageService.generatePreview( + composition.scenes[0] as Scene, + ); const user = await this.templateRepository.create( TemplateEntity.initializeNew({ @@ -70,7 +81,7 @@ class TemplateService implements Service { public async updateTemplate( id: string, - payload: UpdateVideoRequestDto, + payload: UpdateVideoRequestDto & { previewUrl?: string }, userId: string, ): Promise