forked from 77media/video-flow
新增上传图片到七牛云功能,更新角色实体结构以使用 tags 替代 tagIds,重构获取角色列表逻辑以支持新接口,增加根据图片获取角色实体数据的方法。
This commit is contained in:
parent
7d5bc5115c
commit
c48b706e9a
@ -2,6 +2,7 @@ import { useState, useCallback, useMemo } from 'react';
|
|||||||
import { RoleEntity, AITextEntity } from '../domain/Entities';
|
import { RoleEntity, AITextEntity } from '../domain/Entities';
|
||||||
import { RoleEditUseCase } from '../usecase/RoleEditUseCase';
|
import { RoleEditUseCase } from '../usecase/RoleEditUseCase';
|
||||||
import { getRoleData, getRoleList, getUserRoleLibrary, replaceRole } from '@/api/video_flow';
|
import { getRoleData, getRoleList, getUserRoleLibrary, replaceRole } from '@/api/video_flow';
|
||||||
|
import { getUploadToken, uploadToQiniu } from '@/api/common';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色服务Hook返回值接口
|
* 角色服务Hook返回值接口
|
||||||
@ -33,6 +34,8 @@ interface UseRoleService {
|
|||||||
fetchUserRoleLibrary: () => Promise<void>;
|
fetchUserRoleLibrary: () => Promise<void>;
|
||||||
/** 替换角色 */
|
/** 替换角色 */
|
||||||
replaceRoleWithLibrary: (replaceRoleId: string) => Promise<void>;
|
replaceRoleWithLibrary: (replaceRoleId: string) => Promise<void>;
|
||||||
|
/** 上传图片到七牛云 */
|
||||||
|
uploadImageToQiniu: (file: File) => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -292,6 +295,23 @@ export const useRoleServiceHook = (): UseRoleService => {
|
|||||||
}
|
}
|
||||||
}, [selectedRole, roleEditUseCase, userRoleLibrary, initializeRoleData]);
|
}, [selectedRole, roleEditUseCase, userRoleLibrary, initializeRoleData]);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 上传图片到七牛云
|
||||||
|
* @description 上传图片文件到七牛云存储
|
||||||
|
* @param file 要上传的文件
|
||||||
|
* @returns {Promise<string>} 上传成功后的图片URL
|
||||||
|
*/
|
||||||
|
const uploadImageToQiniu = useCallback(async (file: File) => {
|
||||||
|
try {
|
||||||
|
const { token } = await getUploadToken();
|
||||||
|
const url = await uploadToQiniu(file, token);
|
||||||
|
const roleEntity = await roleEditUseCase?.getRoleByImage(url);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('上传图片到七牛云失败:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}, [roleEditUseCase]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// 响应式数据
|
// 响应式数据
|
||||||
roleList,
|
roleList,
|
||||||
@ -308,5 +328,6 @@ export const useRoleServiceHook = (): UseRoleService => {
|
|||||||
regenerateRole,
|
regenerateRole,
|
||||||
fetchUserRoleLibrary,
|
fetchUserRoleLibrary,
|
||||||
replaceRoleWithLibrary,
|
replaceRoleWithLibrary,
|
||||||
|
uploadImageToQiniu
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@ -37,7 +37,7 @@ export interface RoleEntity extends BaseEntity {
|
|||||||
/** 角色提示词 */
|
/** 角色提示词 */
|
||||||
generateText: string;
|
generateText: string;
|
||||||
/**角色标签 */
|
/**角色标签 */
|
||||||
tagIds: TagValueObject[];
|
tags: TagValueObject[];
|
||||||
/** 角色图片URL */
|
/** 角色图片URL */
|
||||||
imageUrl: string;
|
imageUrl: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { VideoFlowProjectResponse } from '@/api/allMovieType';
|
||||||
import { RoleEntity } from '../domain/Entities';
|
import { RoleEntity } from '../domain/Entities';
|
||||||
import {
|
import {
|
||||||
applyRoleToShots,
|
applyRoleToShots,
|
||||||
@ -7,7 +8,8 @@ import {
|
|||||||
regenerateRole,
|
regenerateRole,
|
||||||
getRoleShots,
|
getRoleShots,
|
||||||
replaceRole,
|
replaceRole,
|
||||||
optimizeRoleDescription
|
optimizeRoleDescription,
|
||||||
|
detailScriptEpisodeNew
|
||||||
} from '@/api/video_flow';
|
} from '@/api/video_flow';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,11 +32,13 @@ export class RoleEditUseCase {
|
|||||||
*/
|
*/
|
||||||
async getRoleList(projectId: string): Promise<RoleEntity[]> {
|
async getRoleList(projectId: string): Promise<RoleEntity[]> {
|
||||||
try {
|
try {
|
||||||
const response = await getRoleList({ projectId });
|
// const response = await getRoleList({ projectId });
|
||||||
if (response.successful) {
|
const detail = await detailScriptEpisodeNew({ project_id: projectId });
|
||||||
return response.data;
|
const roleList = this.parseRoleList(detail.data);
|
||||||
|
if (detail.successful) {
|
||||||
|
return roleList;
|
||||||
} else {
|
} else {
|
||||||
throw new Error(response.message || '获取角色列表失败');
|
throw new Error(detail.message || '获取角色列表失败');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取角色列表失败:', error);
|
console.error('获取角色列表失败:', error);
|
||||||
@ -42,6 +46,25 @@ export class RoleEditUseCase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
parseRoleList(detail: VideoFlowProjectResponse): RoleEntity[] {
|
||||||
|
const characters = detail.data?.character || [];
|
||||||
|
|
||||||
|
return characters.map((char, index) => {
|
||||||
|
const roleEntity: RoleEntity = {
|
||||||
|
id: `role_${index + 1}`,
|
||||||
|
name: char.name || '',
|
||||||
|
generateText: char.description || '',
|
||||||
|
tags: [], // 默认为空标签数组
|
||||||
|
imageUrl: '', // 默认为空图片URL
|
||||||
|
loadingProgress: 100, // 默认加载完成
|
||||||
|
disableEdit: false, // 默认允许编辑
|
||||||
|
updatedAt: Date.now()
|
||||||
|
};
|
||||||
|
|
||||||
|
return roleEntity;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取角色库的角色列表
|
* 获取角色库的角色列表
|
||||||
* @returns Promise<RoleEntity[]> 角色库列表
|
* @returns Promise<RoleEntity[]> 角色库列表
|
||||||
@ -224,4 +247,36 @@ export class RoleEditUseCase {
|
|||||||
// 例如:解析文本中的关键词、特征描述等作为标签
|
// 例如:解析文本中的关键词、特征描述等作为标签
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 根据图片地址获取角色实体数据
|
||||||
|
* @param imageUrl 图片地址
|
||||||
|
* @returns Promise<RoleEntity> 角色实体数据
|
||||||
|
*/
|
||||||
|
async getRoleByImage(imageUrl: string): Promise<RoleEntity> {
|
||||||
|
try {
|
||||||
|
// TODO: 调用后端API,根据图片地址获取角色数据
|
||||||
|
// 这里需要根据实际的后端API接口来实现
|
||||||
|
// const response = await getRoleByImage({ imageUrl });
|
||||||
|
|
||||||
|
// 临时实现:返回一个模拟的角色实体
|
||||||
|
// 实际使用时需要替换为真实的API调用
|
||||||
|
const mockRole: RoleEntity = {
|
||||||
|
id: `role_${Date.now()}`,
|
||||||
|
name: '从图片识别的角色',
|
||||||
|
generateText: '通过图片识别生成的角色描述',
|
||||||
|
tagIds: [], // 空标签数组
|
||||||
|
imageUrl: imageUrl, // 使用传入的图片地址
|
||||||
|
loadingProgress: 100, // 加载完成
|
||||||
|
disableEdit: false, // 允许编辑
|
||||||
|
updatedAt: Date.now()
|
||||||
|
};
|
||||||
|
|
||||||
|
return mockRole;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('根据图片获取角色失败:', error);
|
||||||
|
throw new Error('根据图片获取角色失败');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user