fix: bypass vip98k media fetch cache on retry

This commit is contained in:
134 2026-09-07 12:40:58 +08:00 committed by root
parent c69ddb1bb3
commit 002ab8b98d
3 changed files with 32 additions and 1 deletions

View File

@ -12,6 +12,7 @@ import {
import { VIP98K_BASE_URL, normalizeVip98kBaseUrl } from "@/lib/ai/vip98k-models"; import { VIP98K_BASE_URL, normalizeVip98kBaseUrl } from "@/lib/ai/vip98k-models";
import { shouldResolveVip98kResultDelivery } from "@/lib/ai/vip98k-result-delivery"; import { shouldResolveVip98kResultDelivery } from "@/lib/ai/vip98k-result-delivery";
import { import {
addVip98kReferenceRetryToken,
getStorageObjectKeyFromPublicUrl, getStorageObjectKeyFromPublicUrl,
getVip98kStagedMediaRetryDelay, getVip98kStagedMediaRetryDelay,
shouldStageVip98kReferenceUrl, shouldStageVip98kReferenceUrl,
@ -809,13 +810,27 @@ async function submitTask(params: {
const maxAttempts = stagedReferences.length > 0 ? 3 : 1; const maxAttempts = stagedReferences.length > 0 ? 3 : 1;
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) { for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
const requestBody =
attempt === 1 || !Array.isArray(params.body.file_urls)
? params.body
: {
...params.body,
file_urls: params.body.file_urls.map((value) =>
typeof value === "string" && isStagedReferenceUrl(value)
? addVip98kReferenceRetryToken(
value,
`${Date.now()}-${attempt}`,
)
: value,
),
};
const response = await fetch(`${baseURL}${path}`, { const response = await fetch(`${baseURL}${path}`, {
method: String(params.method || "POST").toUpperCase(), method: String(params.method || "POST").toUpperCase(),
headers: { headers: {
Authorization: `Bearer ${params.apiKey}`, Authorization: `Bearer ${params.apiKey}`,
"Content-Type": params.contentType || "application/json", "Content-Type": params.contentType || "application/json",
}, },
body: JSON.stringify(params.body), body: JSON.stringify(requestBody),
signal: AbortSignal.timeout(120_000), signal: AbortSignal.timeout(120_000),
}); });
const payload = await parseJsonResponse(response); const payload = await parseJsonResponse(response);

View File

@ -69,3 +69,10 @@ export function getVip98kStagedMediaRetryDelay(params: {
} }
return params.attempt * 20_000; return params.attempt * 20_000;
} }
export function addVip98kReferenceRetryToken(mediaUrl: string, token: string) {
const parsed = parseUrl(mediaUrl);
if (!parsed) return mediaUrl;
parsed.searchParams.set("sg_media_retry", token);
return parsed.toString();
}

View File

@ -10,6 +10,7 @@ import {
isVip98kImageModelVisible, isVip98kImageModelVisible,
} from "@/lib/ai/vip98k-models"; } from "@/lib/ai/vip98k-models";
import { import {
addVip98kReferenceRetryToken,
getStorageObjectKeyFromPublicUrl, getStorageObjectKeyFromPublicUrl,
getVip98kStagedMediaRetryDelay, getVip98kStagedMediaRetryDelay,
shouldStageVip98kReferenceUrl, shouldStageVip98kReferenceUrl,
@ -77,6 +78,14 @@ test.describe("VIP98K reference-image routing", () => {
stagedReferenceCount: 2, stagedReferenceCount: 2,
}), }),
).toBeNull(); ).toBeNull();
expect(
addVip98kReferenceRetryToken(
"https://cdn.example/reference.jpg?existing=1",
"retry-2",
),
).toBe(
"https://cdn.example/reference.jpg?existing=1&sg_media_retry=retry-2",
);
}); });
test("shows the newly published Nano Banana Pro image editor", () => { test("shows the newly published Nano Banana Pro image editor", () => {