forked from 77media/video-flow
164 lines
4.3 KiB
TypeScript
164 lines
4.3 KiB
TypeScript
import { VideoSegmentEntityAdapter } from "../adapter/oldErrAdapter";
|
||
import { VideoSegmentEntity } from "../domain/Entities";
|
||
import { LensType } from "../domain/valueObject";
|
||
import {
|
||
getShotList,
|
||
regenerateShot,
|
||
optimizeShotContent,
|
||
updateShotPrompt,
|
||
} from "@/api/video_flow";
|
||
|
||
/**
|
||
* 视频片段编辑用例
|
||
* 负责视频片段内容的初始化、修改和优化
|
||
*/
|
||
export class VideoSegmentEditUseCase {
|
||
private loading: boolean = false;
|
||
|
||
/**
|
||
* @description 获取视频片段列表
|
||
* @param projectId 项目ID
|
||
* @returns Promise<VideoSegmentEntity[]> 视频片段列表
|
||
*/
|
||
async getVideoSegmentList(projectId: string): Promise<VideoSegmentEntity[]> {
|
||
try {
|
||
this.loading = true;
|
||
|
||
const response = await getShotList({ project_id: projectId });
|
||
|
||
if (!response.successful) {
|
||
throw new Error(response.message || "获取视频片段列表失败");
|
||
}
|
||
|
||
return VideoSegmentEntityAdapter.toVideoSegmentEntity(response.data) || [];
|
||
} catch (error) {
|
||
console.error("获取视频片段列表失败:", error);
|
||
throw error;
|
||
} finally {
|
||
this.loading = false;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @description 保存分镜提示词数据
|
||
* @param project_id 项目ID
|
||
* @param shot_id 分镜ID
|
||
* @param shot_descriptions 镜头描述数据
|
||
* @returns Promise<any> 保存结果
|
||
*/
|
||
async saveShotPrompt(
|
||
project_id: string,
|
||
shot_id: string,
|
||
shot_descriptions: LensType[]
|
||
): Promise<any> {
|
||
try {
|
||
this.loading = true;
|
||
|
||
const response = await updateShotPrompt({
|
||
project_id,
|
||
shot_id,
|
||
shot_descriptions,
|
||
});
|
||
|
||
if (!response.successful) {
|
||
throw new Error(response.message || "保存分镜提示词数据失败");
|
||
}
|
||
|
||
return response.data;
|
||
} catch (error) {
|
||
console.error("保存分镜提示词数据失败:", error);
|
||
throw error;
|
||
} finally {
|
||
this.loading = false;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @description 通过视频镜头描述数据重新生成视频
|
||
* @param project_id 项目ID
|
||
* @param shot_descriptions 镜头描述数据
|
||
* @param shot_id 视频片段ID(可选,如果重新生成现有片段)
|
||
* @param roleReplaceParams 角色替换参数(可选)
|
||
* @param sceneReplaceParams 场景替换参数(可选)
|
||
* @returns Promise<VideoSegmentEntity> 重新生成的视频片段
|
||
*/
|
||
async regenerateVideoSegment(
|
||
project_id: string,
|
||
shot_descriptions: LensType[],
|
||
shot_id?: string,
|
||
roleReplaceParams?: { oldId: string; newId: string }[],
|
||
sceneReplaceParams?: { oldId: string; newId: string }[]
|
||
): Promise<VideoSegmentEntity> {
|
||
try {
|
||
this.loading = true;
|
||
|
||
// 如果有shot_id,先保存分镜数据
|
||
if (shot_id) {
|
||
await this.saveShotPrompt(project_id, shot_id, shot_descriptions);
|
||
}
|
||
|
||
const response = await regenerateShot({
|
||
project_id,
|
||
shot_id,
|
||
shot_descriptions,
|
||
roleReplaceParams,
|
||
sceneReplaceParams,
|
||
});
|
||
|
||
if (!response.successful) {
|
||
throw new Error(response.message || "重新生成视频片段失败");
|
||
}
|
||
|
||
return response.data;
|
||
} catch (error) {
|
||
console.error("重新生成视频片段失败:", error);
|
||
throw error;
|
||
} finally {
|
||
this.loading = false;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @description 通过AI优化镜头数据(包含对话内容)
|
||
* @param shotId 视频片段ID
|
||
* @param userRequirement 用户优化需求
|
||
* @param lensData 镜头数据数组
|
||
* @returns Promise<LensType[]> 优化后的镜头数据
|
||
*/
|
||
async optimizeVideoContent(
|
||
shotId: string,
|
||
userRequirement: string,
|
||
lensData: LensType[]
|
||
): Promise<LensType[]> {
|
||
try {
|
||
this.loading = true;
|
||
|
||
// 调用AI优化接口
|
||
const response = await optimizeShotContent({
|
||
shotId,
|
||
userRequirement,
|
||
lensData,
|
||
});
|
||
|
||
if (!response.successful) {
|
||
throw new Error(response.message || "AI优化视频内容失败");
|
||
}
|
||
|
||
return response.data;
|
||
} catch (error) {
|
||
console.error("AI优化视频内容失败:", error);
|
||
throw error;
|
||
} finally {
|
||
this.loading = false;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @description 获取加载状态
|
||
* @returns boolean 是否正在加载
|
||
*/
|
||
isLoading(): boolean {
|
||
return this.loading;
|
||
}
|
||
}
|