feat: 对接 generateVideo 页面后端接口
- 新增 uploadFile 工具函数用于图片上传 - 更新 useTemplateActions hook 使用 handleError 统一错误处理 - 实现 generateVideo 页面视频生成功能 - 根据 formSchema.startNodes 动态构建请求数据 - 支持图片和文本输入 - 添加 loading 状态和错误提示 - 生成成功后显示通知并返回 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
25
lib/uploadFile.ts
Normal file
25
lib/uploadFile.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { root } from '@repo/core'
|
||||
import { FileController } from '@repo/sdk'
|
||||
import { Platform } from 'react-native'
|
||||
|
||||
import { handleError } from '@/hooks/use-error'
|
||||
|
||||
export async function uploadFile(params: { uri: string; mimeType?: string; fileName?: string }): Promise<string> {
|
||||
const { uri, mimeType, fileName } = params
|
||||
const file = {
|
||||
name: fileName || 'uploaded_file.jpg',
|
||||
type: mimeType || 'image/jpeg',
|
||||
uri: Platform.OS === 'android' ? uri : uri.replace('file://', ''),
|
||||
}
|
||||
const formData = new FormData()
|
||||
formData.append('file', file as any)
|
||||
|
||||
const fileController = root.get(FileController)
|
||||
const { data, error } = await handleError(async () => await fileController.uploadS3(formData))
|
||||
|
||||
if (error || !data?.data) {
|
||||
throw error || new Error('上传失败')
|
||||
}
|
||||
|
||||
return data.data
|
||||
}
|
||||
Reference in New Issue
Block a user