From 2ccaab0e72c45f59282ce825020cc264b2e45cbb Mon Sep 17 00:00:00 2001 From: WuYongJie Date: Thu, 4 Jun 2026 09:06:49 +0800 Subject: [PATCH] fix: preserve material storage texture urls --- .../src/lib/material-asset-path.ts | 19 ++++++++++++++----- .../src/lib/material-config.test.ts | 9 +++++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/furniture-3d-system/src/lib/material-asset-path.ts b/furniture-3d-system/src/lib/material-asset-path.ts index 51ba4f27..a8b4b6a7 100644 --- a/furniture-3d-system/src/lib/material-asset-path.ts +++ b/furniture-3d-system/src/lib/material-asset-path.ts @@ -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 diff --git a/furniture-3d-system/src/lib/material-config.test.ts b/furniture-3d-system/src/lib/material-config.test.ts index fcb7e654..fc2b3f3f 100644 --- a/furniture-3d-system/src/lib/material-config.test.ts +++ b/furniture-3d-system/src/lib/material-config.test.ts @@ -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) + }) })