fix: tolerate blank creative job requests

This commit is contained in:
2026-05-25 14:46:36 +08:00
parent a69ab8106b
commit a02c5eb48c
3 changed files with 40 additions and 5 deletions

View File

@@ -378,9 +378,18 @@ export async function generateCreativeCopy(body: {
}
export async function createCreativeImageJob(file?: File | null): Promise<Job> {
const fd = new FormData()
if (file) fd.append("file", file)
const res = await fetch(`${API_BASE}/creative/jobs/image`, { method: "POST", body: fd })
const init: RequestInit = file
? (() => {
const fd = new FormData()
fd.append("file", file)
return { method: "POST", body: fd }
})()
: {
method: "POST",
headers: { "Content-Type": "application/json" },
body: "{}",
}
const res = await fetch(`${API_BASE}/creative/jobs/image`, init)
if (!res.ok) {
const txt = await res.text().catch(() => "")
throw apiError("createCreativeImageJob", res.status, txt)