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`
|
||||
}
|
||||
@@ -35,14 +35,6 @@ function buildFallbackSrc(src: string, width: number): string {
|
||||
return `/uploads-resized/${pathPrefix}${parsed.uuid}.webp?w=${width}`
|
||||
}
|
||||
|
||||
/** 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`
|
||||
}
|
||||
|
||||
export function OptimizedImage({
|
||||
src,
|
||||
alt,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { OptimizedImage, getOriginalWebpUrl } from '@/shared/ui/OptimizedImage'
|
||||
import { getOriginalWebpUrl } from '@/shared/lib/get-original-webp-url'
|
||||
import { OptimizedImage } from '@/shared/ui/OptimizedImage'
|
||||
|
||||
describe('OptimizedImage', () => {
|
||||
it('renders a plain img for non-upload URLs', () => {
|
||||
|
||||
Reference in New Issue
Block a user