]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - shared/extra-utils/videos/video-captions.ts
Merge branch 'release/2.1.0' into develop
[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'
40e87e9e
C
5
6const expect = chai.expect
7
8function createVideoCaption (args: {
a1587156 9 url: string
40e87e9e
C
10 accessToken: string
11 videoId: string | number
12 language: string
a1587156
C
13 fixture: string
14 mimeType?: string
2769e297 15 statusCodeExpected?: number
40e87e9e
C
16}) {
17 const path = '/api/v1/videos/' + args.videoId + '/captions/' + args.language
18
2769e297
C
19 const captionfile = buildAbsoluteFixturePath(args.fixture)
20 const captionfileAttach = args.mimeType ? [ captionfile, { contentType: args.mimeType } ] : captionfile
21
40e87e9e
C
22 return makeUploadRequest({
23 method: 'PUT',
24 url: args.url,
25 path,
26 token: args.accessToken,
27 fields: {},
28 attaches: {
2769e297 29 captionfile: captionfileAttach
40e87e9e 30 },
2769e297 31 statusCodeExpected: args.statusCodeExpected || 204
40e87e9e
C
32 })
33}
34
35function listVideoCaptions (url: string, videoId: string | number) {
36 const path = '/api/v1/videos/' + videoId + '/captions'
37
38 return makeGetRequest({
39 url,
40 path,
41 statusCodeExpected: 200
42 })
43}
44
45function deleteVideoCaption (url: string, token: string, videoId: string | number, language: string) {
46 const path = '/api/v1/videos/' + videoId + '/captions/' + language
47
48 return makeDeleteRequest({
49 url,
50 token,
51 path,
52 statusCodeExpected: 204
53 })
54}
55
56async function testCaptionFile (url: string, captionPath: string, containsString: string) {
57 const res = await request(url)
58 .get(captionPath)
59 .expect(200)
60
61 expect(res.text).to.contain(containsString)
62}
63
64// ---------------------------------------------------------------------------
65
66export {
67 createVideoCaption,
68 listVideoCaptions,
69 testCaptionFile,
70 deleteVideoCaption
71}