From d6d6c60d59f488f616823fc5f1516cc8b1ddb7e1 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Tue, 22 Sep 2026 10:07:54 +0000 Subject: [PATCH] fix: send the workspace token when downloading a cloud asset MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit createAssetDownload built a 'fetch' download without a fetch function, so downloadFileAsBlob fell back to bare fetch. That sends no Authorization header, so /api/assets/{id}/content authenticated by session cookie, which resolves to the caller's personal workspace — an asset owned by any other workspace answered 404 and the download failed. Route it through api.fetchApi, which carries the selected workspace's token, matching resolveReplyAssetDownload in the agent download path. apiURL is idempotent for /api-prefixed routes and api_base is '' on cloud, so passing the built content URL back through it is a no-op. --- .../composables/useMediaAssetActions.test.ts | 29 +++++++++++++++++++ .../composables/useMediaAssetActions.ts | 14 +++++++-- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/src/platform/assets/composables/useMediaAssetActions.test.ts b/src/platform/assets/composables/useMediaAssetActions.test.ts index 8b6b2fdab65..8c96c5a310e 100644 --- a/src/platform/assets/composables/useMediaAssetActions.test.ts +++ b/src/platform/assets/composables/useMediaAssetActions.test.ts @@ -148,6 +148,7 @@ const mockTrackExport = vi.hoisted(() => vi.fn()) vi.mock(import('@/scripts/api'), () => ({ api: { deleteItem: vi.fn(), + fetchApi: vi.fn(() => Promise.resolve(new Response())), apiURL: vi.fn((path: string) => `http://localhost:8188/api${path}`), internalURL: vi.fn((path: string) => `http://localhost:8188${path}`), addEventListener: vi.fn(), @@ -649,6 +650,34 @@ describe('useMediaAssetActions', () => { expect(mockTrackExport).not.toHaveBeenCalled() }) + it('fetches a cloud download through the workspace-authenticated client', async () => { + mockIsCloud.value = true + mockGetOutputAssetMetadata.mockReturnValue({ + jobId: 'job1', + outputCount: 1 + }) + + const actions = useMediaAssetActions() + actions.downloadAssets([ + createMockAsset({ + id: 'team-owned', + name: 'team-owned.glb', + tags: ['output'], + user_metadata: { jobId: 'job1', outputCount: 1 } + }) + ]) + + const contentUrl = 'http://localhost:8188/api/assets/team-owned/content' + expect(mockDownloadFileAsBlob).toHaveBeenCalledWith( + contentUrl, + expect.objectContaining({ fetch: expect.any(Function) }) + ) + + const { fetch: authedFetch } = mockDownloadFileAsBlob.mock.calls[0][1] + await authedFetch(contentUrl) + expect(api.fetchApi).toHaveBeenCalledWith(contentUrl) + }) + it('preserves successful OSS downloads when another file fails', async () => { const failure = new Error('download failed') mockDownloadFile diff --git a/src/platform/assets/composables/useMediaAssetActions.ts b/src/platform/assets/composables/useMediaAssetActions.ts index 8cc6632813e..8ebdb45440d 100644 --- a/src/platform/assets/composables/useMediaAssetActions.ts +++ b/src/platform/assets/composables/useMediaAssetActions.ts @@ -130,10 +130,18 @@ export function useMediaAssetActions() { } function createAssetDownload(asset: AssetItem): AssetDownload { + const url = getAssetFileUrl(asset) + const filename = getAssetDisplayName(asset) + if (!isCloud) return { mode: 'direct', url, filename } + + // Required: a bare fetch sends no Authorization header and authenticates by + // session cookie, which resolves to the personal workspace — an asset owned + // by any other workspace then reads as missing. return { - mode: isCloud ? 'fetch' : 'direct', - url: getAssetFileUrl(asset), - filename: getAssetDisplayName(asset) + mode: 'fetch', + url, + filename, + fetch: (route) => api.fetchApi(route) } }