feat: 添加图像转视频功能

- 新增ImageToVideoParams接口定义
- 实现imageToVideo方法支持图像转视频API调用
- 使用application/x-www-form-urlencoded格式发送POST请求
- 支持img_url和duration参数配置
- 添加完整的错误处理和日志记录
This commit is contained in:
imeepos 2025-09-02 18:25:01 +08:00
parent a27577dd3c
commit 2994b68063
1 changed files with 64 additions and 1 deletions

View File

@ -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<string> 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<string> {
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<string>;
if (!result.status) {
throw new Error(result.msg || '图像转视频请求失败');
}
console.log('图像转视频任务提交成功:', result.data);
return result.data;
} catch (error) {
console.error('图像转视频失败:', error);
throw error;
}
}
}
/**