From 6401faf9f07ccbb0cfcea7dde1daf9b76375e6a4 Mon Sep 17 00:00:00 2001 From: oyi77 Date: Tue, 19 May 2026 00:12:55 +0700 Subject: [PATCH] =?UTF-8?q?fix(content):=20address=20Gemini=20review=20?= =?UTF-8?q?=E2=80=94=20error=20checks,=20auth=20consistency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 7 fixes from code review: - Add image download error checks in haiper/leonardo/ideogram handlers - Add audio download error checks in suno/udio handlers - Use providerConfig.statusUrl for suno polling (not hardcoded URL) - Fix suno authType to "cookie" in providerRegistry Co-Authored-By: OpenClaude (mimo-v2.5-pro) --- open-sse/config/providerRegistry.ts | 2 +- open-sse/handlers/imageGeneration.ts | 23 ++++++++++++++++++++++- open-sse/handlers/musicGeneration.ts | 16 +++++++++++++++- 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/open-sse/config/providerRegistry.ts b/open-sse/config/providerRegistry.ts index 390c746776..883a55d149 100644 --- a/open-sse/config/providerRegistry.ts +++ b/open-sse/config/providerRegistry.ts @@ -1986,7 +1986,7 @@ export const REGISTRY: Record = { format: "openai", executor: "default", baseUrl: "https://studio-api.suno.ai/api/generate/v2/", - authType: "apikey", + authType: "cookie", authHeader: "cookie", models: [ { id: "chirp-v3-5", name: "Chirp V3.5" }, diff --git a/open-sse/handlers/imageGeneration.ts b/open-sse/handlers/imageGeneration.ts index 2291e34819..5dbb3eff02 100644 --- a/open-sse/handlers/imageGeneration.ts +++ b/open-sse/handlers/imageGeneration.ts @@ -3018,7 +3018,7 @@ async function handleHaiperImageGeneration({ const res = await fetch(providerConfig.baseUrl, { method: "POST", headers: { "Content-Type": "application/json", HAIPER_KEY: token }, - body: JSON.stringify({ prompt, aspect_ratio: "16:9" }), + body: JSON.stringify({ prompt, aspect_ratio: body.aspect_ratio || "16:9" }), }); if (!res.ok) { const errorText = await res.text(); @@ -3045,6 +3045,13 @@ async function handleHaiperImageGeneration({ const imgUrl = status.creation_url || status.output?.image_url; if (imgUrl) { const imgRes = await fetch(imgUrl); + if (!imgRes.ok) { + return { + success: false, + status: imgRes.status, + error: `Failed to download image: ${imgRes.status}`, + }; + } const buf = await imgRes.arrayBuffer(); saveCallLog({ method: "POST", @@ -3166,6 +3173,13 @@ async function handleLeonardoImageGeneration({ const imgUrl = gen.generated_images?.[0]?.url; if (imgUrl) { const imgRes = await fetch(imgUrl); + if (!imgRes.ok) { + return { + success: false, + status: imgRes.status, + error: `Failed to download image: ${imgRes.status}`, + }; + } const buf = await imgRes.arrayBuffer(); saveCallLog({ method: "POST", @@ -3259,6 +3273,13 @@ async function handleIdeogramImageGeneration({ if (data.data && data.data.length > 0) { const imgUrl = data.data[0].url; const imgRes = await fetch(imgUrl); + if (!imgRes.ok) { + return { + success: false, + status: imgRes.status, + error: `Failed to download image: ${imgRes.status}`, + }; + } const buf = await imgRes.arrayBuffer(); saveCallLog({ method: "POST", diff --git a/open-sse/handlers/musicGeneration.ts b/open-sse/handlers/musicGeneration.ts index bebfeb703c..6528f3ec6d 100644 --- a/open-sse/handlers/musicGeneration.ts +++ b/open-sse/handlers/musicGeneration.ts @@ -434,13 +434,20 @@ async function handleSunoMusicGeneration({ const deadline = Date.now() + 300000; while (Date.now() < deadline) { await new Promise((r) => setTimeout(r, 5000)); - const feedRes = await fetch(`https://studio-api.suno.ai/api/feed/?ids=${ids.join(",")}`, { + const feedRes = await fetch(`${providerConfig.statusUrl}?ids=${ids.join(",")}`, { headers: { Cookie: cookie }, }); const songs = await feedRes.json(); const ready = songs.filter((s) => s.audio_url); if (ready.length > 0) { const audioRes = await fetch(ready[0].audio_url); + if (!audioRes.ok) { + return { + success: false, + status: audioRes.status, + error: `Failed to download audio: ${audioRes.status}`, + }; + } const buf = await audioRes.arrayBuffer(); saveCallLog({ method: "POST", @@ -545,6 +552,13 @@ async function handleUdioMusicGeneration({ const ready = songs.filter((s) => s.finished && s.song_path); if (ready.length > 0) { const audioRes = await fetch(ready[0].song_path); + if (!audioRes.ok) { + return { + success: false, + status: audioRes.status, + error: `Failed to download audio: ${audioRes.status}`, + }; + } const buf = await audioRes.arrayBuffer(); saveCallLog({ method: "POST",