This commit is contained in:
zlwu committed 2025-12-24 15:56:59 +08:00
1 parent 8783150883
commit e86cae8515
1 file changed
+25 -3
+25 -3
View File
@@ -231,13 +231,35 @@ const getUrlsByDirectUrls = async (urls: string[]): Promise<string[]> => {
const blobUrls: string[] = [];
for (const url of urls) {
if (url.trim()) {
const blobUrl = await getImageBlobUrl(url.trim());
if (!url.trim()) {
continue;
}
const u = url.trim();
// 如果已经是 blob / data URL,直接使用
if (u.startsWith('blob:') || u.startsWith('data:')) {
blobUrls.push(u);
continue;
}
// 如果是本地静态资源(例如 Vite 打包的 /src 或 assets 路径),或者是绝对路径但不是受保护的下载接口,
// 直接使用 URL,不经由带认证的请求去获取(避免对静态资源发带 token 的 XHR 导致失败)
const isHttp = /^https?:\/\//i.test(u);
const isProtectedDownload = u.startsWith('/resource/oss/download/');
const isLocalAsset = u.startsWith('/src') || u.startsWith('/assets') || (u.startsWith('/') && !isProtectedDownload && !isHttp);
if (isLocalAsset || isHttp) {
// 对于 http(s) 链接直接使用原始 URL(多数第三方/公开图片可直接加载)
blobUrls.push(u);
continue;
}
// 对于受保护的资源或需认证获取的场景,使用认证请求获取 blob 并创建 blob URL
const blobUrl = await getImageBlobUrl(u);
if (blobUrl) {
blobUrls.push(blobUrl);
}
}
}
return blobUrls;
};