2026-09-17 11:51:03 +08:00
|
|
|
/**
|
|
|
|
|
* Utility functions for URL manipulation and resolution in UXP plugins.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Resolves an asset URL (such as a thumbnail or file download) against
|
|
|
|
|
* the user-configured Shumai endpoint.
|
|
|
|
|
*
|
|
|
|
|
* Handles:
|
2026-09-17 16:37:11 +08:00
|
|
|
* - Relative paths (/files/..., /api/...) by prepending the endpoint.
|
|
|
|
|
* - Absolute URLs (http://, https://) are preserved as-is.
|
2026-09-17 11:51:03 +08:00
|
|
|
*/
|
|
|
|
|
export function resolveAssetUrl(url?: string | null, endpoint?: string): string | undefined {
|
|
|
|
|
if (!url) return undefined
|
|
|
|
|
if (!endpoint) return url
|
|
|
|
|
|
|
|
|
|
const cleanEndpoint = endpoint.replace(/\/+$/, '')
|
|
|
|
|
|
2026-09-17 16:37:11 +08:00
|
|
|
// Handle relative URLs (e.g. /files/..., /api/...)
|
|
|
|
|
if (url.startsWith('/') && !url.startsWith('//')) {
|
|
|
|
|
return `${cleanEndpoint}${url}`
|
2026-09-17 11:51:03 +08:00
|
|
|
}
|
|
|
|
|
|
2026-09-17 16:37:11 +08:00
|
|
|
return url
|
2026-09-17 11:51:03 +08:00
|
|
|
}
|