dynamic images of products
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
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}`
|
||||
}
|
||||
Reference in New Issue
Block a user