18 lines
451 B
TypeScript
18 lines
451 B
TypeScript
import { baseURL } from '@/themeConfig'
|
|||
|
|
|
||
|
|
export interface ProductFile {
|
||
|
|
id?: number
|
||
|
|
url?: string | null
|
||
|
|
src?: string
|
||
|
|
}
|
||
|
|
|
||
|
|
export function getFileUrl(file?: ProductFile | null): string | null {
|
||
|
|
if (!file) return null
|
||
|
|
if (file.url) return file.url
|
||
|
|
if (!file.src) return null
|
||
|
|
if (/^https?:\/\//i.test(file.src)) return file.src
|
||
|
|
const base = baseURL.replace(/\/$/, '')
|
||
|
|
const path = file.src.replace(/^\//, '')
|
||
|
|
return `${base}/${path}`
|
||
|
|
}
|