diff options
author | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2021-07-21 15:51:30 +0200 |
commit | a24bd1ed41b43790bab6ba789580bb4e85f07d85 (patch) | |
tree | a54b0f6c921ba83a6e909cd0ced325b2d4b8863c /shared/extra-utils/videos/captions-command.ts | |
parent | 5f26f13b3c16ac5ae0a3b0a7142d84a9528cf565 (diff) | |
parent | c63830f15403ac4e750829f27d8bbbdc9a59282c (diff) | |
download | PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.gz PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.tar.zst PeerTube-a24bd1ed41b43790bab6ba789580bb4e85f07d85.zip |
Merge branch 'next' into develop
Diffstat (limited to 'shared/extra-utils/videos/captions-command.ts')
-rw-r--r-- | shared/extra-utils/videos/captions-command.ts | 65 |
1 files changed, 65 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..a65ea99e3 --- /dev/null +++ b/shared/extra-utils/videos/captions-command.ts | |||
@@ -0,0 +1,65 @@ | |||
1 | import { HttpStatusCode, ResultList, VideoCaption } from '@shared/models' | ||
2 | import { buildAbsoluteFixturePath } from '../miscs' | ||
3 | import { AbstractCommand, OverrideCommandOptions } from '../shared' | ||
4 | |||
5 | export class CaptionsCommand extends AbstractCommand { | ||
6 | |||
7 | add (options: OverrideCommandOptions & { | ||
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 | |||
35 | list (options: OverrideCommandOptions & { | ||
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 | |||
50 | delete (options: OverrideCommandOptions & { | ||
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 | } | ||