cdn and packages building

This commit is contained in:
wass08
2026-02-04 09:53:44 +09:00
parent 4036f370e7
commit e776ce9849
14 changed files with 205 additions and 28 deletions
+51
View File
@@ -0,0 +1,51 @@
import { loadAssetUrl } from '@pascal-app/core'
export const ASSETS_CDN_URL = 'https://pascal-cdn.wawasensei.dev'
/**
* Resolves an asset URL to the appropriate format:
* - If URL starts with http:// or https://, return as-is (external URL)
* - If URL starts with asset://, resolve from IndexedDB storage
* - If URL starts with /, prepend CDN URL (absolute path)
* - Otherwise, prepend CDN URL (relative path)
*/
export async function resolveAssetUrl(url: string | undefined | null): Promise<string | null> {
if (!url) return null
// External URL - use as-is
if (url.startsWith('http://') || url.startsWith('https://')) {
return url
}
// IndexedDB asset - resolve from storage
if (url.startsWith('asset://')) {
return loadAssetUrl(url)
}
// Absolute or relative path - prepend CDN URL
const normalizedPath = url.startsWith('/') ? url : `/${url}`
return `${ASSETS_CDN_URL}${normalizedPath}`
}
/**
* Synchronous version for URLs that don't need IndexedDB resolution
* Only use this if you're sure the URL is not an asset:// URL
*/
export function resolveCdnUrl(url: string | undefined | null): string | null {
if (!url) return null
// External URL - use as-is
if (url.startsWith('http://') || url.startsWith('https://')) {
return url
}
// Don't use this for asset:// URLs - use resolveAssetUrl instead
if (url.startsWith('asset://')) {
console.warn('Use resolveAssetUrl() for asset:// URLs, not resolveCdnUrl()')
return null
}
// Absolute or relative path - prepend CDN URL
const normalizedPath = url.startsWith('/') ? url : `/${url}`
return `${ASSETS_CDN_URL}${normalizedPath}`
}