diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-08 11:49:38 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-20 15:27:17 +0200 |
commit | a2470c9f4bfc7f49f4b94de935bacdd53fd54f29 (patch) | |
tree | cb6b6b33d1a404fe31547c004241a7eb9743b64e /shared/extra-utils/videos/captions-command.ts | |
parent | e3d15a6a9aed97a004d9dac1b7a6499d794e080a (diff) | |
download | PeerTube-a2470c9f4bfc7f49f4b94de935bacdd53fd54f29.tar.gz PeerTube-a2470c9f4bfc7f49f4b94de935bacdd53fd54f29.tar.zst PeerTube-a2470c9f4bfc7f49f4b94de935bacdd53fd54f29.zip |
Introduce captions command
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 | } | ||