fix: preserve material storage texture urls

This commit is contained in:
WuYongJie 2026-06-04 09:06:49 +08:00
parent 8d0930a5b2
commit 2ccaab0e72
2 changed files with 23 additions and 5 deletions

View File

@ -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

View File

@ -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)
})
})