Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/platform/assets/composables/useMediaAssetActions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ const mockTrackExport = vi.hoisted(() => vi.fn())
vi.mock<unknown>(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(),
Expand Down Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions src/platform/assets/composables/useMediaAssetActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
Loading