fix: preserve material storage texture urls
This commit is contained in:
parent
8d0930a5b2
commit
2ccaab0e72
@ -47,11 +47,8 @@ export function normalizeMaterialAssetPath(rawPath: string | null | undefined):
|
||||
return toLocalMaterialAssetPath(rawPath)
|
||||
}
|
||||
|
||||
export function encodeLocalMaterialAssetUrl(rawPath: string | null | undefined): string | null {
|
||||
const normalized = normalizeMaterialAssetPath(rawPath)
|
||||
if (!normalized) return null
|
||||
|
||||
return normalized
|
||||
function encodeLocalPathname(pathname: string): string {
|
||||
return pathname
|
||||
.split('/')
|
||||
.map((segment, index) => {
|
||||
if (index === 0) return ''
|
||||
@ -64,6 +61,18 @@ export function encodeLocalMaterialAssetUrl(rawPath: string | null | undefined):
|
||||
.join('/')
|
||||
}
|
||||
|
||||
export function encodeLocalMaterialAssetUrl(rawPath: string | null | undefined): string | null {
|
||||
const normalized = normalizeMaterialAssetPath(rawPath)
|
||||
if (!normalized) return null
|
||||
|
||||
try {
|
||||
const parsed = new URL(normalized, 'http://material.local')
|
||||
return `${encodeLocalPathname(parsed.pathname)}${parsed.search}${parsed.hash}`
|
||||
} catch {
|
||||
return encodeLocalPathname(normalized)
|
||||
}
|
||||
}
|
||||
|
||||
export function isDefaultMaterialThumbnailPath(rawPath: string | null | undefined): boolean {
|
||||
const normalized = normalizeMaterialAssetPath(rawPath)
|
||||
return normalized ? DEFAULT_MATERIAL_THUMBNAIL_PATHS.has(normalized) : false
|
||||
|
||||
@ -36,4 +36,13 @@ describe('material-config', () => {
|
||||
)
|
||||
expect(config?.thumbnailUrl).toBe(config?.textureUrl)
|
||||
})
|
||||
|
||||
it('preserves storage proxy query strings when encoding material texture urls', () => {
|
||||
const textureUrl =
|
||||
'/api/storage/object?key=prod%2Fmaterials%2Ftextures%2Fmaterial-library%2F%E5%8C%97%E7%BE%8E%E9%BB%91%E8%83%A1%E6%A1%83_1780533522979.webp'
|
||||
const config = toMaterialConfig(createMaterial({ textureUrl }))
|
||||
|
||||
expect(config?.textureUrl).toBe(textureUrl)
|
||||
expect(config?.thumbnailUrl).toBe(textureUrl)
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user