video-flow-b/app/service/usecase/templateStoryUseCase.ts
2025-08-23 01:30:24 +08:00

67 lines
1.9 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { generateCharacterBrief } from "@/api/video_flow";
import { StoryTemplateEntity } from "../domain/Entities";
import { getTemplateStoryList } from "@/api/movie_start";
/**
* 模板故事用例
* 负责管理故事模板的获取与操作
*/
export class TemplateStoryUseCase {
/** 故事模板列表 */
templateStoryList: StoryTemplateEntity[] = [];
/** 当前选中的故事模板 */
selectedTemplate: StoryTemplateEntity | null = null;
constructor() {}
/**
* 获取故事模板列表
* @returns {Promise<StoryTemplateEntity[]>} - 故事模板实体数组
*/
async getTemplateStoryList(): Promise<StoryTemplateEntity[]> {
try {
const response = await getTemplateStoryList();
if (response.successful && response.data) {
this.templateStoryList = response.data.items;
return response.data.items;
}
throw new Error(response.message || "获取故事模板列表失败");
} catch (error) {
console.error("获取故事模板列表失败:", error);
throw error;
}
}
/**
* 上传人物头像并分析特征,
* @returns {Promise<{crop_url: string, whisk_caption: string}>} 返回新的头像URL和特征描述
*/
async AvatarAndAnalyzeFeatures(
imageUrl: string
): Promise<{ crop_url: string; whisk_caption: string }> {
// 直接在这里处理上传和分析逻辑
try {
// 2. 调用AI分析接口获取人物特征描述
const analysisResult = await generateCharacterBrief({
image_url: imageUrl,
});
if (!analysisResult.successful || !analysisResult.data) {
throw new Error("人物特征分析失败");
}
// 3. 返回新的头像URL和特征描述用于替换旧数据
const result = {
crop_url: imageUrl,
whisk_caption: JSON.stringify(analysisResult.data.character_brief),
};
return result;
} catch (error) {
throw error;
}
}
}