diff --git a/app/src/lib/utilities/model-utilities.ts b/app/src/lib/utilities/model-utilities.ts index 3aac35f..5fa6889 100644 --- a/app/src/lib/utilities/model-utilities.ts +++ b/app/src/lib/utilities/model-utilities.ts @@ -28,14 +28,15 @@ export const cacheModelFiles = async () => { const files = uzip.parse(await data.arrayBuffer()) for (const [path, data] of Object.entries(files) as [path: string, data: Uint8Array][]) { - const url = new URL(path, window.location.href) - fileService?.saveFile(url.toString(), data) + const normalizedPath = path.startsWith('/') ? path : '/' + path + const resolvedUrl = resolve(normalizedPath as any) + fileService?.saveFile(resolvedUrl, data) + fileService?.saveFile(normalizedPath, data) } } export const loadModel = async (url: string): Promise> => { const urdfLoader = new URDFLoader() - urdfLoader.workingPath = resolve('/') let xml = url.endsWith('.xacro') ? await loadXacro(url) : await fetch(url).then(res => res.text()) diff --git a/app/src/routes/+layout.ts b/app/src/routes/+layout.ts index 84f7629..7ab36f6 100644 --- a/app/src/routes/+layout.ts +++ b/app/src/routes/+layout.ts @@ -6,10 +6,20 @@ const registerFetchIntercept = async () => { const fileService = (await import('$lib/services/file-service')).default window.fetch = async (resource, config) => { const url = resource instanceof Request ? resource.url : resource.toString() - const file = await fileService?.getFile(url) - return file?.isOk() && file.inner ? - new Response(new Uint8Array(file.inner)) - : originalFetch(resource, config) + + let file = await fileService?.getFile(url) + if (file?.isOk() && file.inner) return new Response(new Uint8Array(file.inner)) + + if (url.startsWith('http')) { + try { + const urlObj = new URL(url) + const pathOnly = urlObj.pathname + file = await fileService?.getFile(pathOnly) + if (file?.isOk() && file.inner) return new Response(new Uint8Array(file.inner)) + } catch {} + } + + return originalFetch(resource, config) } }