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