aboutsummaryrefslogtreecommitdiffhomepage
path: root/packages/server-commands/src/videos/captions-command.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/server-commands/src/videos/captions-command.ts')
-rw-r--r--packages/server-commands/src/videos/captions-command.ts67
1 files changed, 67 insertions, 0 deletions
diff --git a/packages/server-commands/src/videos/captions-command.ts b/packages/server-commands/src/videos/captions-command.ts
new file mode 100644
index 000000000..a8336aa27
--- /dev/null
+++ b/packages/server-commands/src/videos/captions-command.ts
@@ -0,0 +1,67 @@
1import { HttpStatusCode, ResultList, VideoCaption } from '@peertube/peertube-models'
2import { buildAbsoluteFixturePath } from '@peertube/peertube-node-utils'
3import { AbstractCommand, OverrideCommandOptions } from '../shared/index.js'
4
5export 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 videoPassword?: string
38 }) {
39 const { videoId, videoPassword } = options
40 const path = '/api/v1/videos/' + videoId + '/captions'
41
42 return this.getRequestBody<ResultList<VideoCaption>>({
43 ...options,
44
45 path,
46 headers: this.buildVideoPasswordHeader(videoPassword),
47 implicitToken: false,
48 defaultExpectedStatus: HttpStatusCode.OK_200
49 })
50 }
51
52 delete (options: OverrideCommandOptions & {
53 videoId: string | number
54 language: string
55 }) {
56 const { videoId, language } = options
57 const path = '/api/v1/videos/' + videoId + '/captions/' + language
58
59 return this.deleteRequest({
60 ...options,
61
62 path,
63 implicitToken: true,
64 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
65 })
66 }
67}