fix: 图片URL双重/api/v1前缀导致404

根因: 后端返回 /api/v1/upload/files/xxx.jpg
      前端imageUrl又拼VITE_API_BASE_URL=/api/v1
      → /api/v1/api/v1/upload/files/xxx.jpg → 404
修复: /api/开头的URL直接返回, 不再拼接前缀
This commit is contained in:
2026-08-13 09:07:10 +08:00
parent b8ade13b61
commit f056cc8625

View File

@ -28,7 +28,12 @@ function parseImages(s: any): string[] {
if (typeof s === "string") { try { return JSON.parse(s); } catch { return []; } }
return [];
}
function imageUrl(u: string) { if (!u) return ""; return u.startsWith("http") ? u : import.meta.env.VITE_API_BASE_URL + (u.startsWith("/") ? u : "/" + u); }
function imageUrl(u: string) {
if (!u) return "";
if (u.startsWith("http")) return u; // 绝对地址直接用
if (u.startsWith("/api/")) return u; // 已是完整API路径避免双重/api/v1前缀
return import.meta.env.VITE_API_BASE_URL + (u.startsWith("/") ? u : "/" + u);
}
const ALL_TASKS = new Set<TaskResponse>();
function collectAll(tasks: TaskResponse[]) { tasks.forEach(t => { ALL_TASKS.add(t); if (t.child_tasks) collectAll(t.child_tasks); }); }