🐛 fix: 修复 template run 数据格式与 identifier 缺失问题

主要修复:
1.  添加 transformFormDataToRunFormat 函数转换表单数据
2.  根据节点类型正确格式化数据:
   - image: { images: [{ url: "..." }] }
   - video: { videos: [{ url: "..." }] }
   - text: { texts: ["..."] }
   - select: { selections: "..." } (单选) / ["..."] (多选)
3.  添加 identifier 字段到 API 请求
4.  从 storage 获取用户 session 作为 identifier

修复问题:
-  之前:{ "data": { "node_xxx": "blob:..." } }
-  现在:{ "data": { "node_xxx": { "images": [{ "url": "..." }] } }, "identifier": "user-id" }

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
imeepos
2025-11-11 18:30:03 +08:00
parent 5ad83146ad
commit 74ca367081
2 changed files with 80 additions and 4 deletions

View File

@@ -1,10 +1,27 @@
import { apiClient } from './client';
import { RunTemplateResponse, TemplateGenerationResponse, RunTemplateData } from '../types/template-run';
import { storage } from '../storage';
export async function runTemplate(templateId: string, data: RunTemplateData): Promise<RunTemplateResponse> {
// 从 storage 获取用户 session 作为 identifier
const sessionStr = await storage.getItem('session');
let identifier = 'anonymous';
if (sessionStr) {
try {
const session = JSON.parse(sessionStr);
identifier = session?.user?.id || 'anonymous';
} catch (error) {
console.warn('Failed to parse session:', error);
}
}
return apiClient<RunTemplateResponse>(`/api/templates/${templateId}/run`, {
method: 'POST',
body: JSON.stringify({ data }),
body: JSON.stringify({
data,
identifier,
}),
});
}