fix(web): 修复图片 URL 拼接逻辑,/api/ 路径支持公网域名去重拼接
This commit is contained in:
@ -30,9 +30,18 @@ function parseImages(s: any): string[] {
|
||||
}
|
||||
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);
|
||||
if (u.startsWith("http")) return u; // 已是完整绝对地址(含跨域域名),直接用
|
||||
const base = (import.meta.env.VITE_API_BASE_URL || "").replace(/\/+$/, ""); // 去掉末尾斜杠
|
||||
const path = u.startsWith("/") ? u : "/" + u;
|
||||
// 后端图片固定返回 /api/v1/upload/files/... 这类 /api/ 开头的相对路径,
|
||||
// 需拼上 base 才能访问到后端;同时避免重复前缀:
|
||||
// - base 为纯域名(如 https://track_back.iris-rs.cn)→ 正常 base + path
|
||||
// - base 以 /api 或 /api/v1 结尾 → 先剥掉该段,否则会拼出 /api/api/ 或 /api/v1/api/v1
|
||||
if (path.startsWith("/api/")) {
|
||||
const origin = base.replace(/\/api(\/v\d+)?$/, "");
|
||||
return origin + path;
|
||||
}
|
||||
return base + path;
|
||||
}
|
||||
|
||||
const ALL_TASKS = new Set<TaskResponse>();
|
||||
|
||||
Reference in New Issue
Block a user