diff --git a/src/sdk/index.ts b/src/sdk/index.ts index e8142b5..7a63da9 100644 --- a/src/sdk/index.ts +++ b/src/sdk/index.ts @@ -40,6 +40,16 @@ interface GenerateImageParams { img_file: string; } +/** + * 图像转视频请求参数 + */ +interface ImageToVideoParams { + /** 图像URL地址 */ + img_url: string; + /** 视频时长,默认为0 */ + duration?: number; +} + export function isGetFileInfoSuccessCallbackResult(val: any): val is Taro.getFileInfo.SuccessCallbackResult { return val && Reflect.has(val, 'digest') } @@ -164,7 +174,7 @@ export class BowongAISDK { sourceType }); - console.log({chooseResult}) + console.log({ chooseResult }) // 选择图片完成后触发回调 onImageSelected?.(); @@ -338,6 +348,59 @@ export class BowongAISDK { throw new Error(`查询任务状态失败,已重试${maxRetries}次: ${error instanceof Error ? error.message : String(error)}`); } } + + + + /** + * 图像转视频 + * @param params 图像转视频参数 + * @returns Promise 返回任务ID + * + * 对应 curl 命令: + * curl -X 'POST' \ + * 'https://bowongai-test--text-video-agent-fastapi-app.modal.run/api/custom/transform/i2v' \ + * -H 'accept: application/json' \ + * -H 'Content-Type: application/x-www-form-urlencoded' \ + * -d 'img_url=string&duration=0' + */ + async imageToVideo(params: ImageToVideoParams): Promise { + const { img_url, duration = 0 } = params; + const url = `${this.baseUrl}/api/custom/transform/i2v`; + + try { + // 构建 form data + const formData = new URLSearchParams(); + formData.append('img_url', img_url); + formData.append('duration', duration.toString()); + + const response = await Taro.request({ + url, + method: 'POST', + header: { + 'accept': 'application/json', + 'Content-Type': 'application/x-www-form-urlencoded' + }, + data: formData.toString() + }); + + if (response.statusCode !== 200) { + throw new Error(`HTTP ${response.statusCode}: 图像转视频请求失败`); + } + + const result = response.data as ApiResponse; + + if (!result.status) { + throw new Error(result.msg || '图像转视频请求失败'); + } + + console.log('图像转视频任务提交成功:', result.data); + return result.data; + + } catch (error) { + console.error('图像转视频失败:', error); + throw error; + } + } } /**