aboutsummaryrefslogtreecommitdiffhomepage
path: root/shared
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-08 11:49:38 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:17 +0200
commita2470c9f4bfc7f49f4b94de935bacdd53fd54f29 (patch)
treecb6b6b33d1a404fe31547c004241a7eb9743b64e /shared
parente3d15a6a9aed97a004d9dac1b7a6499d794e080a (diff)
downloadPeerTube-a2470c9f4bfc7f49f4b94de935bacdd53fd54f29.tar.gz
PeerTube-a2470c9f4bfc7f49f4b94de935bacdd53fd54f29.tar.zst
PeerTube-a2470c9f4bfc7f49f4b94de935bacdd53fd54f29.zip
Introduce captions command
Diffstat (limited to 'shared')
-rw-r--r--shared/extra-utils/server/servers.ts4
-rw-r--r--shared/extra-utils/videos/captions-command.ts66
-rw-r--r--shared/extra-utils/videos/captions.ts17
-rw-r--r--shared/extra-utils/videos/index.ts3
-rw-r--r--shared/extra-utils/videos/video-captions.ts72
5 files changed, 88 insertions, 74 deletions
diff --git a/shared/extra-utils/server/servers.ts b/shared/extra-utils/server/servers.ts
index a4432902f..170360341 100644
--- a/shared/extra-utils/server/servers.ts
+++ b/shared/extra-utils/server/servers.ts
@@ -18,7 +18,7 @@ import { makeGetRequest } from '../requests/requests'
18import { SearchCommand } from '../search' 18import { SearchCommand } from '../search'
19import { SocketIOCommand } from '../socket' 19import { SocketIOCommand } from '../socket'
20import { AccountsCommand, BlocklistCommand, SubscriptionsCommand } from '../users' 20import { AccountsCommand, BlocklistCommand, SubscriptionsCommand } from '../users'
21import { LiveCommand, ServicesCommand, BlacklistCommand } from '../videos' 21import { LiveCommand, ServicesCommand, BlacklistCommand, CaptionsCommand } from '../videos'
22import { ConfigCommand } from './config-command' 22import { ConfigCommand } from './config-command'
23import { ContactFormCommand } from './contact-form-command' 23import { ContactFormCommand } from './contact-form-command'
24import { DebugCommand } from './debug-command' 24import { DebugCommand } from './debug-command'
@@ -103,6 +103,7 @@ interface ServerInfo {
103 liveCommand?: LiveCommand 103 liveCommand?: LiveCommand
104 servicesCommand?: ServicesCommand 104 servicesCommand?: ServicesCommand
105 blacklistCommand?: BlacklistCommand 105 blacklistCommand?: BlacklistCommand
106 captionsCommand?: CaptionsCommand
106} 107}
107 108
108function parallelTests () { 109function parallelTests () {
@@ -331,6 +332,7 @@ async function runServer (server: ServerInfo, configOverrideArg?: any, args = []
331 server.liveCommand = new LiveCommand(server) 332 server.liveCommand = new LiveCommand(server)
332 server.servicesCommand = new ServicesCommand(server) 333 server.servicesCommand = new ServicesCommand(server)
333 server.blacklistCommand = new BlacklistCommand(server) 334 server.blacklistCommand = new BlacklistCommand(server)
335 server.captionsCommand = new CaptionsCommand(server)
334 336
335 res(server) 337 res(server)
336 }) 338 })
diff --git a/shared/extra-utils/videos/captions-command.ts b/shared/extra-utils/videos/captions-command.ts
new file mode 100644
index 000000000..908b6dae6
--- /dev/null
+++ b/shared/extra-utils/videos/captions-command.ts
@@ -0,0 +1,66 @@
1import { ResultList, VideoCaption } from '@shared/models'
2import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
3import { buildAbsoluteFixturePath } from '../miscs/miscs'
4import { AbstractCommand, OverrideCommandOptions } from '../shared'
5
6export class CaptionsCommand extends AbstractCommand {
7
8 createVideoCaption (options: OverrideCommandOptions & {
9 videoId: string | number
10 language: string
11 fixture: string
12 mimeType?: string
13 }) {
14 const { videoId, language, fixture, mimeType } = options
15
16 const path = '/api/v1/videos/' + videoId + '/captions/' + language
17
18 const captionfile = buildAbsoluteFixturePath(fixture)
19 const captionfileAttach = mimeType
20 ? [ captionfile, { contentType: mimeType } ]
21 : captionfile
22
23 return this.putUploadRequest({
24 ...options,
25
26 path,
27 fields: {},
28 attaches: {
29 captionfile: captionfileAttach
30 },
31 implicitToken: true,
32 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
33 })
34 }
35
36 listVideoCaptions (options: OverrideCommandOptions & {
37 videoId: string | number
38 }) {
39 const { videoId } = options
40 const path = '/api/v1/videos/' + videoId + '/captions'
41
42 return this.getRequestBody<ResultList<VideoCaption>>({
43 ...options,
44
45 path,
46 implicitToken: false,
47 defaultExpectedStatus: HttpStatusCode.OK_200
48 })
49 }
50
51 deleteVideoCaption (options: OverrideCommandOptions & {
52 videoId: string | number
53 language: string
54 }) {
55 const { videoId, language } = options
56 const path = '/api/v1/videos/' + videoId + '/captions/' + language
57
58 return this.deleteRequest({
59 ...options,
60
61 path,
62 implicitToken: true,
63 defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
64 })
65 }
66}
diff --git a/shared/extra-utils/videos/captions.ts b/shared/extra-utils/videos/captions.ts
new file mode 100644
index 000000000..2246bd133
--- /dev/null
+++ b/shared/extra-utils/videos/captions.ts
@@ -0,0 +1,17 @@
1import { expect } from 'chai'
2import * as request from 'supertest'
3import { HttpStatusCode } from '../../core-utils/miscs/http-error-codes'
4
5async function testCaptionFile (url: string, captionPath: string, containsString: string) {
6 const res = await request(url)
7 .get(captionPath)
8 .expect(HttpStatusCode.OK_200)
9
10 expect(res.text).to.contain(containsString)
11}
12
13// ---------------------------------------------------------------------------
14
15export {
16 testCaptionFile
17}
diff --git a/shared/extra-utils/videos/index.ts b/shared/extra-utils/videos/index.ts
index 67f5faf54..03b4756d5 100644
--- a/shared/extra-utils/videos/index.ts
+++ b/shared/extra-utils/videos/index.ts
@@ -1,8 +1,9 @@
1export * from './blacklist-command' 1export * from './blacklist-command'
2export * from './captions'
3export * from './captions-command'
2export * from './live-command' 4export * from './live-command'
3export * from './live' 5export * from './live'
4export * from './services-command' 6export * from './services-command'
5export * from './video-captions'
6export * from './video-change-ownership' 7export * from './video-change-ownership'
7export * from './video-channels' 8export * from './video-channels'
8export * from './video-comments' 9export * from './video-comments'
diff --git a/shared/extra-utils/videos/video-captions.ts b/shared/extra-utils/videos/video-captions.ts
deleted file mode 100644
index 62eec7b90..000000000
--- a/shared/extra-utils/videos/video-captions.ts
+++ /dev/null
@@ -1,72 +0,0 @@
1import { makeDeleteRequest, makeGetRequest, makeUploadRequest } from '../requests/requests'
2import * as request from 'supertest'
3import * as chai from 'chai'
4import { buildAbsoluteFixturePath } from '../miscs/miscs'
5import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
6
7const expect = chai.expect
8
9function createVideoCaption (args: {
10 url: string
11 accessToken: string
12 videoId: string | number
13 language: string
14 fixture: string
15 mimeType?: string
16 statusCodeExpected?: number
17}) {
18 const path = '/api/v1/videos/' + args.videoId + '/captions/' + args.language
19
20 const captionfile = buildAbsoluteFixturePath(args.fixture)
21 const captionfileAttach = args.mimeType ? [ captionfile, { contentType: args.mimeType } ] : captionfile
22
23 return makeUploadRequest({
24 method: 'PUT',
25 url: args.url,
26 path,
27 token: args.accessToken,
28 fields: {},
29 attaches: {
30 captionfile: captionfileAttach
31 },
32 statusCodeExpected: args.statusCodeExpected || HttpStatusCode.NO_CONTENT_204
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,
42 statusCodeExpected: HttpStatusCode.OK_200
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,
53 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
54 })
55}
56
57async function testCaptionFile (url: string, captionPath: string, containsString: string) {
58 const res = await request(url)
59 .get(captionPath)
60 .expect(HttpStatusCode.OK_200)
61
62 expect(res.text).to.contain(containsString)
63}
64
65// ---------------------------------------------------------------------------
66
67export {
68 createVideoCaption,
69 listVideoCaptions,
70 testCaptionFile,
71 deleteVideoCaption
72}