]>
Commit | Line | Data |
---|---|---|
c0e8b12e | 1 | import { HttpStatusCode } from '@shared/models' |
a2470c9f | 2 | import { ResultList, VideoCaption } from '@shared/models' |
6c5065a0 | 3 | import { buildAbsoluteFixturePath } from '../miscs' |
a2470c9f C |
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 | } |