diff options
author | buoyantair <buoyantair@gmail.com> | 2018-10-29 22:18:31 +0530 |
---|---|---|
committer | buoyantair <buoyantair@gmail.com> | 2018-10-29 22:18:31 +0530 |
commit | 9639bd175726b73f8fe664b5ced12a72407b1f0b (patch) | |
tree | 689d4c9e0a1f8dcc55e0ba4e694af3b09bff2cad /shared/utils/videos/video-captions.ts | |
parent | 71607e4a65d3a8904bcd418ab7acbc2f34f725ff (diff) | |
download | PeerTube-9639bd175726b73f8fe664b5ced12a72407b1f0b.tar.gz PeerTube-9639bd175726b73f8fe664b5ced12a72407b1f0b.tar.zst PeerTube-9639bd175726b73f8fe664b5ced12a72407b1f0b.zip |
Move utils to /shared
Move utils used by /server/tools/* & /server/tests/**/* into
/shared folder.
Issue: #1336
Diffstat (limited to 'shared/utils/videos/video-captions.ts')
-rw-r--r-- | shared/utils/videos/video-captions.ts | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/shared/utils/videos/video-captions.ts b/shared/utils/videos/video-captions.ts new file mode 100644 index 000000000..41e52be07 --- /dev/null +++ b/shared/utils/videos/video-captions.ts | |||
@@ -0,0 +1,71 @@ | |||
1 | import { makeDeleteRequest, makeGetRequest } from '../' | ||
2 | import { buildAbsoluteFixturePath, makeUploadRequest } from '../index' | ||
3 | import * as request from 'supertest' | ||
4 | import * as chai from 'chai' | ||
5 | |||
6 | const expect = chai.expect | ||
7 | |||
8 | function createVideoCaption (args: { | ||
9 | url: string, | ||
10 | accessToken: string | ||
11 | videoId: string | number | ||
12 | language: string | ||
13 | fixture: string, | ||
14 | mimeType?: string, | ||
15 | statusCodeExpected?: number | ||
16 | }) { | ||
17 | const path = '/api/v1/videos/' + args.videoId + '/captions/' + args.language | ||
18 | |||
19 | const captionfile = buildAbsoluteFixturePath(args.fixture) | ||
20 | const captionfileAttach = args.mimeType ? [ captionfile, { contentType: args.mimeType } ] : captionfile | ||
21 | |||
22 | return makeUploadRequest({ | ||
23 | method: 'PUT', | ||
24 | url: args.url, | ||
25 | path, | ||
26 | token: args.accessToken, | ||
27 | fields: {}, | ||
28 | attaches: { | ||
29 | captionfile: captionfileAttach | ||
30 | }, | ||
31 | statusCodeExpected: args.statusCodeExpected || 204 | ||
32 | }) | ||
33 | } | ||
34 | |||
35 | function 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 | |||
45 | function 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 | |||
56 | async 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 | |||
66 | export { | ||
67 | createVideoCaption, | ||
68 | listVideoCaptions, | ||
69 | testCaptionFile, | ||
70 | deleteVideoCaption | ||
71 | } | ||