Skip to content

Commit

Permalink
refactor: use getXBlockAssetsApiUrl to get the library endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
dcoa committed Nov 11, 2024
1 parent 3bdd84a commit 9c189e4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/editors/data/services/cms/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe('cms api', () => {
blockId, learningContextId, studioEndpointUrl, pageNumber: 0,
});
expect(get).toHaveBeenCalledWith(
urls.libraryAssets({ studioEndpointUrl, blockId }),
urls.libraryAssets({ blockId }),
);
});
});
Expand Down Expand Up @@ -289,7 +289,7 @@ describe('cms api', () => {
asset,
});
expect(put).toHaveBeenCalledWith(
`${urls.libraryAssets({ blockId, studioEndpointUrl })}static/${encodeURI(filename)}`,
`${urls.libraryAssets({ blockId, assetName: asset.name })}`,
mockFormdata,
);
});
Expand Down
4 changes: 2 additions & 2 deletions src/editors/data/services/cms/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export const apiMethods = {
}): Promise<{ data: AssetResponse & Pagination }> => {
if (isLibraryKey(learningContextId)) {
return get(
`${urls.libraryAssets({ studioEndpointUrl, blockId })}`,
`${urls.libraryAssets({ blockId })}`,
);
}
const params = {
Expand Down Expand Up @@ -157,7 +157,7 @@ export const apiMethods = {
if (isLibraryKey(learningContextId)) {
data.set('content', asset);
return put(
`${urls.libraryAssets({ blockId, studioEndpointUrl })}static/${encodeURI(asset.name)}`,
`${urls.libraryAssets({ blockId, assetName: asset.name })}`,
data,
);
}
Expand Down
7 changes: 5 additions & 2 deletions src/editors/data/services/cms/urls.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isLibraryKey, isLibraryV1Key } from '../../../../generic/key-utils';
import { getXBlockAssetsApiUrl } from '../../../../library-authoring/data/api';

/**
* A little helper so we can write the types of these functions more compactly
Expand Down Expand Up @@ -61,8 +62,10 @@ export const courseAssets = (({ studioEndpointUrl, learningContextId }) => (
`${studioEndpointUrl}/assets/${learningContextId}/`
)) satisfies UrlFunction;

export const libraryAssets = (({ blockId, studioEndpointUrl }) => (
`${studioEndpointUrl}/api/libraries/v2/blocks/${blockId}/assets/`
export const libraryAssets = (({ blockId, assetName }) => (
assetName
? `${getXBlockAssetsApiUrl(blockId)}static/${encodeURI(assetName)}`
: `${getXBlockAssetsApiUrl(blockId)}`
)) satisfies UrlFunction;

export const thumbnailUpload = (({ studioEndpointUrl, learningContextId, videoId }) => (
Expand Down

0 comments on commit 9c189e4

Please sign in to comment.