forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathurls.ts
More file actions
129 lines (105 loc) · 5.16 KB
/
urls.ts
File metadata and controls
129 lines (105 loc) · 5.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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
* The main purpose of this is to indicate the params are all strings.
*/
type UrlFunction = (args: Record<string, string>) => string;
export const libraryV1 = ({ studioEndpointUrl, learningContextId }) => (
`${studioEndpointUrl}/library/${learningContextId}`
);
export const unit = ({ studioEndpointUrl, unitUrl, blockId }) => (
`${studioEndpointUrl}/container/${unitUrl.data.ancestors[0]?.id}#${blockId}`
);
export const returnUrl = ({
studioEndpointUrl, unitUrl, learningContextId, blockId,
}): string => {
// Is this a v1 library?
if (isLibraryV1Key(learningContextId)) {
// when the learning context is a v1 library, return to the library page
return libraryV1({ studioEndpointUrl, learningContextId });
}
// Is this a v2 library?
if (isLibraryKey(learningContextId)) {
// when it's a v2 library, there will be no return url (instead a closed popup)
// (temporary) don't throw error, just return empty url. it will fail it's network connection but otherwise
// the app will run
// throw new Error('Return url not available (or needed) for V2 libraries');
return '';
}
// when the learning context is a course, return to the unit page
// only do this for v1 blocks
if (unitUrl && blockId.includes('block-v1')) {
return unit({ studioEndpointUrl, unitUrl, blockId });
}
return '';
};
export const block = (({ studioEndpointUrl, blockId }) => (
blockId.startsWith('lb:')
? `${studioEndpointUrl}/api/xblock/v2/xblocks/${blockId}/fields/`
: `${studioEndpointUrl}/xblock/${blockId}`
)) satisfies UrlFunction;
export const blockAncestor = (({ studioEndpointUrl, blockId }) => {
if (blockId.includes('block-v1')) {
return `${block({ studioEndpointUrl, blockId })}?fields=ancestorInfo`;
}
throw new Error('Block ancestor not available (and not needed) for V2 blocks');
}) satisfies UrlFunction;
export const blockStudioView = (({ studioEndpointUrl, blockId }) => (
blockId.includes('block-v1')
? `${block({ studioEndpointUrl, blockId })}/studio_view`
: `${studioEndpointUrl}/api/xblock/v2/xblocks/${blockId}/view/studio_view/`
)) satisfies UrlFunction;
export const courseAssets = (({ studioEndpointUrl, learningContextId }) => (
`${studioEndpointUrl}/assets/${learningContextId}/`
)) satisfies UrlFunction;
export const libraryAssets = (({ blockId, assetName }) => (
assetName
? `${getXBlockAssetsApiUrl(blockId)}static/${encodeURI(assetName)}`
: `${getXBlockAssetsApiUrl(blockId)}`
)) satisfies UrlFunction;
export const thumbnailUpload = (({ studioEndpointUrl, learningContextId, videoId }) => (
`${studioEndpointUrl}/video_images/${learningContextId}/${videoId}`
)) satisfies UrlFunction;
export const videoTranscripts = (({ studioEndpointUrl, blockId }) => (
`${block({ studioEndpointUrl, blockId })}/handler/studio_transcript/translation`
)) satisfies UrlFunction;
export const downloadVideoTranscriptURL = (({ studioEndpointUrl, blockId, language }) => (
`${videoTranscripts({ studioEndpointUrl, blockId })}?language_code=${language}`
)) satisfies UrlFunction;
export const transcriptXblockV2 = (({ transcriptHandlerUrl }) => (
`${transcriptHandlerUrl}translation`
)) satisfies UrlFunction;
export const downloadVideoTranscriptURLV2 = (({ transcriptHandlerUrl, language }) => (
`${transcriptXblockV2({ transcriptHandlerUrl })}?language_code=${language}`
)) satisfies UrlFunction;
export const mediaTranscriptURL = (({ studioEndpointUrl, transcriptUrl }) => (
`${studioEndpointUrl}${transcriptUrl}`
)) satisfies UrlFunction;
export const downloadVideoHandoutUrl = (({ studioEndpointUrl, handout }) => (
`${studioEndpointUrl}${handout}`
)) satisfies UrlFunction;
export const courseDetailsUrl = (({ studioEndpointUrl, learningContextId }) => (
`${studioEndpointUrl}/settings/details/${learningContextId}`
)) satisfies UrlFunction;
export const checkTranscriptsForImport = (({ studioEndpointUrl, parameters }) => (
`${studioEndpointUrl}/transcripts/check?data=${parameters}`
)) satisfies UrlFunction;
export const replaceTranscript = (({ studioEndpointUrl, parameters }) => (
`${studioEndpointUrl}/transcripts/replace?data=${parameters}`
)) satisfies UrlFunction;
export const courseAdvanceSettings = (({ studioEndpointUrl, learningContextId }) => (
`${studioEndpointUrl}/api/contentstore/v0/advanced_settings/${learningContextId}`
)) satisfies UrlFunction;
export const videoFeatures = (({ studioEndpointUrl }) => (
`${studioEndpointUrl}/video_features/`
)) satisfies UrlFunction;
export const courseVideos = (({ studioEndpointUrl, learningContextId }) => (
`${studioEndpointUrl}/videos/${learningContextId}`
)) satisfies UrlFunction;
export const handlerUrl = (({ studioEndpointUrl, blockId, handlerName }) => (
`${studioEndpointUrl}/api/xblock/v2/xblocks/${blockId}/handler_url/${handlerName}/`
)) satisfies UrlFunction;
export const validateNumericInputUrl = (({ studioEndpointUrl }) => (
`${studioEndpointUrl}/api/contentstore/v2/validate/numerical-input/`
)) satisfies UrlFunction;