feat: use WebP original for full-screen product image viewer
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
/** Extract UUID and subdir from a /uploads/... URL */
|
||||
function parseUploadUrl(src: string): { uuid: string; ext: string; subdir: string } | null {
|
||||
const match = src.match(/^\/uploads(?:\/(reviews))?\/([^.\\/]+)\.(png|jpe?g|webp)/i)
|
||||
if (!match) return null
|
||||
return { subdir: match[1] || '', uuid: match[2], ext: match[3].toLowerCase() }
|
||||
}
|
||||
|
||||
/** Get the original WebP URL for full-screen display (no resize) */
|
||||
export function getOriginalWebpUrl(src: string): string {
|
||||
const parsed = parseUploadUrl(src)
|
||||
if (!parsed) return src
|
||||
const pathPrefix = parsed.subdir ? `${parsed.subdir}/` : ''
|
||||
return `/uploads/${pathPrefix}${parsed.uuid}.webp`
|
||||
}
|
||||
Reference in New Issue
Block a user