]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/videos/video-captions.ts
Hide schedule privacy if private does not exist
[github/Chocobozzz/PeerTube.git] / shared / extra-utils / videos / video-captions.ts
CommitLineData
d175a6f7 1import { makeDeleteRequest, makeGetRequest, makeUploadRequest } from '../requests/requests'
40e87e9e
C
2import * as request from 'supertest'
3import * as chai from 'chai'
d175a6f7 4import { buildAbsoluteFixturePath } from '../miscs/miscs'
2d53be02 5import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
40e87e9e
C
6
7const expect = chai.expect
8
9function createVideoCaption (args: {
a1587156 10 url: string
40e87e9e
C
11 accessToken: string
12 videoId: string | number
13 language: string
a1587156
C
14 fixture: string
15 mimeType?: string
2769e297 16 statusCodeExpected?: number
40e87e9e
C
17}) {
18 const path = '/api/v1/videos/' + args.videoId + '/captions/' + args.language
19
2769e297
C
20 const captionfile = buildAbsoluteFixturePath(args.fixture)
21 const captionfileAttach = args.mimeType ? [ captionfile, { contentType: args.mimeType } ] : captionfile
22
40e87e9e
C
23 return makeUploadRequest({
24 method: 'PUT',
25 url: args.url,
26 path,
27 token: args.accessToken,
28 fields: {},
29 attaches: {
2769e297 30 captionfile: captionfileAttach
40e87e9e 31 },
2d53be02 32 statusCodeExpected: args.statusCodeExpected || HttpStatusCode.NO_CONTENT_204
40e87e9e
C
33 })
34}
35
36function listVideoCaptions (url: string, videoId: string | number) {
37 const path = '/api/v1/videos/' + videoId + '/captions'
38
39 return makeGetRequest({
40 url,
41 path,
2d53be02 42 statusCodeExpected: HttpStatusCode.OK_200
40e87e9e
C
43 })
44}
45
46function deleteVideoCaption (url: string, token: string, videoId: string | number, language: string) {
47 const path = '/api/v1/videos/' + videoId + '/captions/' + language
48
49 return makeDeleteRequest({
50 url,
51 token,
52 path,
2d53be02 53 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
40e87e9e
C
54 })
55}
56
57async function testCaptionFile (url: string, captionPath: string, containsString: string) {
58 const res = await request(url)
59 .get(captionPath)
2d53be02 60 .expect(HttpStatusCode.OK_200)
40e87e9e
C
61
62 expect(res.text).to.contain(containsString)
63}
64
65// ---------------------------------------------------------------------------
66
67export {
68 createVideoCaption,
69 listVideoCaptions,
70 testCaptionFile,
71 deleteVideoCaption
72}