2026-05-18 10:13:50 +03:30
|
|
|
import { baseURL } from '@/themeConfig'
|
2026-06-03 11:57:40 +03:30
|
|
|
import type { User } from '@/models/login'
|
2026-05-18 10:13:50 +03:30
|
|
|
|
|
|
|
|
export interface ProductFile {
|
|
|
|
|
id?: number
|
|
|
|
|
url?: string | null
|
|
|
|
|
src?: string
|
2026-06-03 11:57:40 +03:30
|
|
|
full_src?: string
|
2026-05-18 10:13:50 +03:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getFileUrl(file?: ProductFile | null): string | null {
|
|
|
|
|
if (!file) return null
|
2026-06-09 21:04:22 +03:30
|
|
|
|
|
|
|
|
for (const value of [file.full_src, file.url, file.src]) {
|
|
|
|
|
if (!value) continue
|
|
|
|
|
if (/^https?:\/\//i.test(value)) return value
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const relative = file.src || file.full_src
|
|
|
|
|
if (!relative) return null
|
|
|
|
|
|
2026-05-18 10:13:50 +03:30
|
|
|
const base = baseURL.replace(/\/$/, '')
|
2026-06-09 21:04:22 +03:30
|
|
|
const path = String(relative).replace(/^\//, '')
|
2026-05-18 10:13:50 +03:30
|
|
|
return `${base}/${path}`
|
|
|
|
|
}
|
2026-06-03 11:57:40 +03:30
|
|
|
|
|
|
|
|
/** Resolve profile avatar URL from GET /customer/me payload */
|
|
|
|
|
export function getUserAvatarUrl(user?: User | null): string | null {
|
|
|
|
|
if (!user) return null
|
|
|
|
|
if (typeof user.avatar_url === 'string' && user.avatar_url) return user.avatar_url
|
|
|
|
|
if (typeof user.full_src === 'string' && user.full_src) return user.full_src
|
|
|
|
|
const nested = user.avatar || user.file
|
|
|
|
|
return getFileUrl(nested as ProductFile | undefined)
|
|
|
|
|
}
|