Files
pda-uniapp/utils/api-url.js
T
2026-08-27 14:30:26 +08:00

16 lines
691 B
JavaScript

export function resolveEvidencePreviewUrl(previewUrl, baseUrl) {
const rawUrl = String(previewUrl || '')
const normalizedBase = String(baseUrl || '').replace(/\/$/, '')
if (!rawUrl || /^https?:\/\//i.test(rawUrl)) return rawUrl
if (/^https?:\/\//i.test(normalizedBase)) {
const origin = normalizedBase.match(/^(https?:\/\/[^/]+)/i)?.[1] || ''
return `${origin}${rawUrl.startsWith('/') ? '' : '/'}${rawUrl}`
}
const platformPrefix = '/api/platform/v1'
if (rawUrl === platformPrefix || rawUrl.startsWith(`${platformPrefix}/`)) {
return `${normalizedBase}${rawUrl.slice(platformPrefix.length)}`
}
if (rawUrl.startsWith('/')) return rawUrl
return `${normalizedBase}/${rawUrl}`
}