feat: video functions

This commit is contained in:
Nevo David 2025-07-14 16:21:06 +07:00
parent a214815f81
commit 9b4621c4b2
6 changed files with 33 additions and 19 deletions

View File

@ -125,4 +125,13 @@ export class PublicIntegrationsController {
) {
return this._mediaService.generateVideo(org, body);
}
@Post('/video/:identifier/:function')
videoFunction(
@Param('identifier') identifier: string,
@Param('function') functionName: string,
@Body('params') body: any
) {
return this._mediaService.videoFunction(identifier, functionName, body);
}
}

View File

@ -129,6 +129,7 @@ export class MediaService {
throw new Error(`Function ${functionName} not found on video instance`);
}
this._videoManager.checkAvailableVideoFunction(functionToCall);
return functionToCall(body);
}
}

View File

@ -1,8 +1,6 @@
import { OpenaiService } from '@gitroom/nestjs-libraries/openai/openai.service';
import {
URL,
Video,
VideoAbstract,
ExposeVideoFunction, URL, Video, VideoAbstract
} from '@gitroom/nestjs-libraries/videos/video.interface';
import { chunk } from 'lodash';
import Transloadit from 'transloadit';
@ -228,6 +226,7 @@ export class ImagesSlides extends VideoAbstract<Params> {
return results.subtitled[0].url;
}
@ExposeVideoFunction()
async loadVoices(data: any) {
const { voices } = await (
await fetch(

View File

@ -39,19 +39,6 @@ export class Veo3 extends VideoAbstract<Params> {
output: 'vertical' | 'horizontal',
customParams: Params
): Promise<URL> {
console.log({
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${process.env.KIEAI_API_KEY}`,
},
method: 'POST',
body: JSON.stringify({
prompt: customParams.prompt,
imageUrls: customParams?.images?.map((p) => p.path) || [],
model: 'veo3_fast',
aspectRatio: output === 'horizontal' ? '16:9' : '9:16',
}),
});
const value = await (
await fetch('https://api.kie.ai/api/v1/veo/generate', {
headers: {

View File

@ -5,9 +5,7 @@ export type URL = string;
export abstract class VideoAbstract<T> {
dto: Type<T>;
async processAndValidate(
customParams?: T
) {
async processAndValidate(customParams?: T) {
const validationPipe = new ValidationPipe({
skipMissingProperties: false,
transform: true,
@ -37,6 +35,16 @@ export interface VideoParams {
trial: boolean;
}
export function ExposeVideoFunction() {
return function (
target: any,
propertyKey: string,
descriptor: PropertyDescriptor
) {
Reflect.defineMetadata('video-function', 'true', descriptor.value);
};
}
export function Video(params: VideoParams) {
return function (target: any) {
// Apply @Injectable decorator to the target class

View File

@ -22,6 +22,16 @@ export class VideoManager {
);
}
checkAvailableVideoFunction(method: any) {
const videoFunction = Reflect.getMetadata('video-function', method);
if (!videoFunction) {
throw new Error(
`Method ${method.name} is not a valid video function.`
);
}
return videoFunction;
}
getVideoByName(
identifier: string
): (VideoParams & { instance: VideoAbstract<any> }) | undefined {