diff --git a/frontend/src/api.js b/frontend/src/api.js index b7d43ea..5449dea 100644 --- a/frontend/src/api.js +++ b/frontend/src/api.js @@ -60,10 +60,9 @@ export function generatedUrl(name) { return `${BASE}/images/${s.replace(/^\/?images\//, '')}` } -/** Load a private image (thumbnail, falling back to the original) using the - * same Bearer token the SPA already has. Returns a browser blob: URL so the - * component can revoke it later. Throws on real failure. */ -export async function loadImageBlob(name, signal) { +/** Fetch a private image (thumbnail first, original as fallback) with the + * SPA's Bearer token. Returns { blob, status } — throws on real failure. */ +async function fetchImageBlob(name, signal) { const headers = auth.token ? { Authorization: `Bearer ${auth.token}` } : {} let u = thumbUrl(name) let r = await fetch(u, { headers, credentials: 'include', signal }) @@ -72,8 +71,24 @@ export async function loadImageBlob(name, signal) { r = await fetch(u, { headers, credentials: 'include', signal }) } if (!r.ok) throw new Error(`图片加载失败 (${r.status})`) - const blob = await r.blob() - return { url: URL.createObjectURL(blob), status: r.status } + return { blob: await r.blob(), status: r.status } +} + +/** Same as fetchImageBlob but returns a revocable blob: URL for /