diff options
Diffstat (limited to 'shared/extra-utils/videos/captions-command.ts')
-rw-r--r-- | shared/extra-utils/videos/captions-command.ts | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/shared/extra-utils/videos/captions-command.ts b/shared/extra-utils/videos/captions-command.ts new file mode 100644 index 000000000..908b6dae6 --- /dev/null +++ b/shared/extra-utils/videos/captions-command.ts | |||
@@ -0,0 +1,66 @@ | |||
1 | import { ResultList, VideoCaption } from '@shared/models' | ||
2 | import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes' | ||
3 | import { buildAbsoluteFixturePath } from '../miscs/miscs' | ||
4 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
5 | |||
6 | export class CaptionsCommand extends AbstractCommand { | ||
7 | |||
8 | createVideoCaption (options: OverrideCommandOptions & { | ||
9 | videoId: string | number | ||
10 | language: string | ||
11 | fixture: string | ||
12 | mimeType?: string | ||
13 | }) { | ||
14 | const { videoId, language, fixture, mimeType } = options | ||
15 | |||
16 | const path = '/api/v1/videos/' + videoId + '/captions/' + language | ||
17 | |||
18 | const captionfile = buildAbsoluteFixturePath(fixture) | ||
19 | const captionfileAttach = mimeType | ||
20 | ? [ captionfile, { contentType: mimeType } ] | ||
21 | : captionfile | ||
22 | |||
23 | return this.putUploadRequest({ | ||
24 | ...options, | ||
25 | |||
26 | path, | ||
27 | fields: {}, | ||
28 | attaches: { | ||
29 | captionfile: captionfileAttach | ||
30 | }, | ||
31 | implicitToken: true, | ||
32 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
33 | }) | ||
34 | } | ||
35 | |||
36 | listVideoCaptions (options: OverrideCommandOptions & { | ||
37 | videoId: string | number | ||
38 | }) { | ||
39 | const { videoId } = options | ||
40 | const path = '/api/v1/videos/' + videoId + '/captions' | ||
41 | |||
42 | return this.getRequestBody<ResultList<VideoCaption>>({ | ||
43 | ...options, | ||
44 | |||
45 | path, | ||
46 | implicitToken: false, | ||
47 | defaultExpectedStatus: HttpStatusCode.OK_200 | ||
48 | }) | ||
49 | } | ||
50 | |||
51 | deleteVideoCaption (options: OverrideCommandOptions & { | ||
52 | videoId: string | number | ||
53 | language: string | ||
54 | }) { | ||
55 | const { videoId, language } = options | ||
56 | const path = '/api/v1/videos/' + videoId + '/captions/' + language | ||
57 | |||
58 | return this.deleteRequest({ | ||
59 | ...options, | ||
60 | |||
61 | path, | ||
62 | implicitToken: true, | ||
63 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | ||
64 | }) | ||
65 | } | ||
66 | } | ||