]>
Commit | Line | Data |
---|---|---|
c55e3d72 | 1 | import { buildAbsoluteFixturePath } from '@shared/core-utils' |
4c7e60bc | 2 | import { HttpStatusCode, ResultList, VideoCaption } from '@shared/models' |
a2470c9f C |
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' |
4 | ||
5 | export class CaptionsCommand extends AbstractCommand { | |
6 | ||
c63830f1 | 7 | add (options: OverrideCommandOptions & { |
a2470c9f C |
8 | videoId: string | number |
9 | language: string | |
10 | fixture: string | |
11 | mimeType?: string | |
12 | }) { | |
13 | const { videoId, language, fixture, mimeType } = options | |
14 | ||
15 | const path = '/api/v1/videos/' + videoId + '/captions/' + language | |
16 | ||
17 | const captionfile = buildAbsoluteFixturePath(fixture) | |
18 | const captionfileAttach = mimeType | |
19 | ? [ captionfile, { contentType: mimeType } ] | |
20 | : captionfile | |
21 | ||
22 | return this.putUploadRequest({ | |
23 | ...options, | |
24 | ||
25 | path, | |
26 | fields: {}, | |
27 | attaches: { | |
28 | captionfile: captionfileAttach | |
29 | }, | |
30 | implicitToken: true, | |
31 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | |
32 | }) | |
33 | } | |
34 | ||
c63830f1 | 35 | list (options: OverrideCommandOptions & { |
a2470c9f C |
36 | videoId: string | number |
37 | }) { | |
38 | const { videoId } = options | |
39 | const path = '/api/v1/videos/' + videoId + '/captions' | |
40 | ||
41 | return this.getRequestBody<ResultList<VideoCaption>>({ | |
42 | ...options, | |
43 | ||
44 | path, | |
45 | implicitToken: false, | |
46 | defaultExpectedStatus: HttpStatusCode.OK_200 | |
47 | }) | |
48 | } | |
49 | ||
c63830f1 | 50 | delete (options: OverrideCommandOptions & { |
a2470c9f C |
51 | videoId: string | number |
52 | language: string | |
53 | }) { | |
54 | const { videoId, language } = options | |
55 | const path = '/api/v1/videos/' + videoId + '/captions/' + language | |
56 | ||
57 | return this.deleteRequest({ | |
58 | ...options, | |
59 | ||
60 | path, | |
61 | implicitToken: true, | |
62 | defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204 | |
63 | }) | |
64 | } | |
65 | } |