forked from 77media/video-flow
53 lines
1.3 KiB
TypeScript
53 lines
1.3 KiB
TypeScript
import { RoleEntity } from '../domain/Entities';
|
|
import { RoleItem, TagItem, TextItem } from '../domain/Item';
|
|
import { regenerateRole, applyRoleToShots } from '@/api/video_flow';
|
|
|
|
/**
|
|
* 角色图编辑用例
|
|
* 负责角色图内容的初始化、修改和优化
|
|
*/
|
|
export class RoleEditUseCase {
|
|
constructor(private roleItem: RoleItem) {
|
|
}
|
|
|
|
/**
|
|
* @description: 重新生成角色
|
|
* @param {TextItem} prompt
|
|
* @param {TagItem[]} tags
|
|
* @return {*}
|
|
*/
|
|
async AIgenerateRole(prompt: TextItem, tags: TagItem[]): Promise<RoleEntity> {
|
|
const promptText = prompt.entity.content;
|
|
const tagList = tags.map((tag) => tag.entity.content);
|
|
|
|
// 调用重新生成角色接口
|
|
const response = await regenerateRole({
|
|
roleId: this.roleItem.entity.id||'',
|
|
prompt: promptText,
|
|
tagTypes: tagList,
|
|
});
|
|
|
|
if (response.successful) {
|
|
const roleEntity = response.data;
|
|
this.roleItem.setEntity(roleEntity);
|
|
return roleEntity;
|
|
} else {
|
|
throw new Error(`重新生成角色失败: ${response.message}`);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* 应用此角色到指定分镜
|
|
* @param shotIds 分镜ID列表
|
|
* @returns 应用结果
|
|
*/
|
|
async applyRole(shotIds: string[]) {
|
|
const roleId = this.roleItem.entity.id;
|
|
return await applyRoleToShots({
|
|
roleId,
|
|
shotIds,
|
|
});
|
|
}
|
|
}
|