aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-08-06 12:11:08 +0200
committerChocobozzz <me@florianbigard.com>2018-08-06 12:11:08 +0200
commit3d52b300ea79bec21f090e2447c4808307078618 (patch)
tree5a68db9d557eb9449533162cf01f974e60b16885
parent60979b076de00a7c7f6dde26617cd39357d9fc6d (diff)
parent2769e297ca6703f761f9b57792585eb1fc5aac49 (diff)
downloadPeerTube-3d52b300ea79bec21f090e2447c4808307078618.tar.gz
PeerTube-3d52b300ea79bec21f090e2447c4808307078618.tar.zst
PeerTube-3d52b300ea79bec21f090e2447c4808307078618.zip
Merge branch 'release/beta-10' into develop
-rw-r--r--package.json2
-rw-r--r--server/helpers/custom-validators/video-captions.ts4
-rw-r--r--server/helpers/express-utils.ts3
-rw-r--r--server/tests/api/check-params/video-captions.ts26
-rw-r--r--server/tests/api/videos/video-captions.ts3
-rw-r--r--server/tests/utils/requests/requests.ts8
-rw-r--r--server/tests/utils/videos/video-captions.ts11
7 files changed, 48 insertions, 9 deletions
diff --git a/package.json b/package.json
index 8627fe9ba..4dbe1717e 100644
--- a/package.json
+++ b/package.json
@@ -171,7 +171,7 @@
171 "chai-json-schema": "^1.5.0", 171 "chai-json-schema": "^1.5.0",
172 "chai-xml": "^0.3.2", 172 "chai-xml": "^0.3.2",
173 "husky": "^1.0.0-rc.4", 173 "husky": "^1.0.0-rc.4",
174 "libxmljs": "0.19.1", 174 "libxmljs": "0.19.0",
175 "lint-staged": "^7.1.0", 175 "lint-staged": "^7.1.0",
176 "maildev": "^1.0.0-rc3", 176 "maildev": "^1.0.0-rc3",
177 "mocha": "^5.0.0", 177 "mocha": "^5.0.0",
diff --git a/server/helpers/custom-validators/video-captions.ts b/server/helpers/custom-validators/video-captions.ts
index 6b1729f36..177e9e86e 100644
--- a/server/helpers/custom-validators/video-captions.ts
+++ b/server/helpers/custom-validators/video-captions.ts
@@ -8,7 +8,9 @@ function isVideoCaptionLanguageValid (value: any) {
8 return exists(value) && VIDEO_LANGUAGES[ value ] !== undefined 8 return exists(value) && VIDEO_LANGUAGES[ value ] !== undefined
9} 9}
10 10
11const videoCaptionTypes = Object.keys(VIDEO_CAPTIONS_MIMETYPE_EXT).map(m => `(${m})`) 11const videoCaptionTypes = Object.keys(VIDEO_CAPTIONS_MIMETYPE_EXT)
12 .concat([ 'application/octet-stream' ]) // MacOS sends application/octet-stream ><
13 .map(m => `(${m})`)
12const videoCaptionTypesRegex = videoCaptionTypes.join('|') 14const videoCaptionTypesRegex = videoCaptionTypes.join('|')
13function isVideoCaptionFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], field: string) { 15function isVideoCaptionFile (files: { [ fieldname: string ]: Express.Multer.File[] } | Express.Multer.File[], field: string) {
14 return isFileValid(files, videoCaptionTypesRegex, field, CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max) 16 return isFileValid(files, videoCaptionTypesRegex, field, CONSTRAINTS_FIELDS.VIDEO_CAPTIONS.CAPTION_FILE.FILE_SIZE.max)
diff --git a/server/helpers/express-utils.ts b/server/helpers/express-utils.ts
index f136a4329..b3cc40848 100644
--- a/server/helpers/express-utils.ts
+++ b/server/helpers/express-utils.ts
@@ -4,6 +4,7 @@ import { CONFIG, REMOTE_SCHEME } from '../initializers'
4import { logger } from './logger' 4import { logger } from './logger'
5import { User } from '../../shared/models/users' 5import { User } from '../../shared/models/users'
6import { generateRandomString } from './utils' 6import { generateRandomString } from './utils'
7import { extname } from 'path'
7 8
8function buildNSFWFilter (res: express.Response, paramNSFW?: string) { 9function buildNSFWFilter (res: express.Response, paramNSFW?: string) {
9 if (paramNSFW === 'true') return true 10 if (paramNSFW === 'true') return true
@@ -50,7 +51,7 @@ function createReqFiles (
50 }, 51 },
51 52
52 filename: async (req, file, cb) => { 53 filename: async (req, file, cb) => {
53 const extension = mimeTypes[ file.mimetype ] 54 const extension = mimeTypes[ file.mimetype ] || extname(file.originalname)
54 let randomString = '' 55 let randomString = ''
55 56
56 try { 57 try {
diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts
index a3d7ac35d..8d46971a1 100644
--- a/server/tests/api/check-params/video-captions.ts
+++ b/server/tests/api/check-params/video-captions.ts
@@ -15,6 +15,7 @@ import {
15 userLogin 15 userLogin
16} from '../../utils' 16} from '../../utils'
17import { join } from 'path' 17import { join } from 'path'
18import { createVideoCaption } from '../../utils/videos/video-captions'
18 19
19describe('Test video captions API validator', function () { 20describe('Test video captions API validator', function () {
20 const path = '/api/v1/videos/' 21 const path = '/api/v1/videos/'
@@ -143,6 +144,31 @@ describe('Test video captions API validator', function () {
143 }) 144 })
144 }) 145 })
145 146
147 // We don't check the extension yet
148 // it('Should fail with an invalid captionfile extension and octet-stream mime type', async function () {
149 // await createVideoCaption({
150 // url: server.url,
151 // accessToken: server.accessToken,
152 // language: 'zh',
153 // videoId: videoUUID,
154 // fixture: 'subtitle-bad.txt',
155 // mimeType: 'application/octet-stream',
156 // statusCodeExpected: 400
157 // })
158 // })
159
160 it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () {
161 await createVideoCaption({
162 url: server.url,
163 accessToken: server.accessToken,
164 language: 'zh',
165 videoId: videoUUID,
166 fixture: 'subtitle-good.srt',
167 mimeType: 'application/octet-stream'
168 })
169 })
170
171 // We don't check the file validity yet
146 // it('Should fail with an invalid captionfile srt', async function () { 172 // it('Should fail with an invalid captionfile srt', async function () {
147 // const attaches = { 173 // const attaches = {
148 // 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.srt') 174 // 'captionfile': join(__dirname, '..', '..', 'fixtures', 'subtitle-bad.srt')
diff --git a/server/tests/api/videos/video-captions.ts b/server/tests/api/videos/video-captions.ts
index eb73c5baf..ba9ebbdd6 100644
--- a/server/tests/api/videos/video-captions.ts
+++ b/server/tests/api/videos/video-captions.ts
@@ -56,7 +56,8 @@ describe('Test video captions', function () {
56 accessToken: servers[0].accessToken, 56 accessToken: servers[0].accessToken,
57 language: 'zh', 57 language: 'zh',
58 videoId: videoUUID, 58 videoId: videoUUID,
59 fixture: 'subtitle-good2.vtt' 59 fixture: 'subtitle-good2.vtt',
60 mimeType: 'application/octet-stream'
60 }) 61 })
61 62
62 await waitJobs(servers) 63 await waitJobs(servers)
diff --git a/server/tests/utils/requests/requests.ts b/server/tests/utils/requests/requests.ts
index b88b3ce5b..fc7b38b8c 100644
--- a/server/tests/utils/requests/requests.ts
+++ b/server/tests/utils/requests/requests.ts
@@ -48,7 +48,7 @@ function makeUploadRequest (options: {
48 path: string, 48 path: string,
49 token?: string, 49 token?: string,
50 fields: { [ fieldName: string ]: any }, 50 fields: { [ fieldName: string ]: any },
51 attaches: { [ attachName: string ]: any }, 51 attaches: { [ attachName: string ]: any | any[] },
52 statusCodeExpected?: number 52 statusCodeExpected?: number
53}) { 53}) {
54 if (!options.statusCodeExpected) options.statusCodeExpected = 400 54 if (!options.statusCodeExpected) options.statusCodeExpected = 400
@@ -78,7 +78,11 @@ function makeUploadRequest (options: {
78 78
79 Object.keys(options.attaches).forEach(attach => { 79 Object.keys(options.attaches).forEach(attach => {
80 const value = options.attaches[attach] 80 const value = options.attaches[attach]
81 req.attach(attach, buildAbsoluteFixturePath(value)) 81 if (Array.isArray(value)) {
82 req.attach(attach, buildAbsoluteFixturePath(value[0]), value[1])
83 } else {
84 req.attach(attach, buildAbsoluteFixturePath(value))
85 }
82 }) 86 })
83 87
84 return req.expect(options.statusCodeExpected) 88 return req.expect(options.statusCodeExpected)
diff --git a/server/tests/utils/videos/video-captions.ts b/server/tests/utils/videos/video-captions.ts
index 207e89632..41e52be07 100644
--- a/server/tests/utils/videos/video-captions.ts
+++ b/server/tests/utils/videos/video-captions.ts
@@ -10,10 +10,15 @@ function createVideoCaption (args: {
10 accessToken: string 10 accessToken: string
11 videoId: string | number 11 videoId: string | number
12 language: string 12 language: string
13 fixture: string 13 fixture: string,
14 mimeType?: string,
15 statusCodeExpected?: number
14}) { 16}) {
15 const path = '/api/v1/videos/' + args.videoId + '/captions/' + args.language 17 const path = '/api/v1/videos/' + args.videoId + '/captions/' + args.language
16 18
19 const captionfile = buildAbsoluteFixturePath(args.fixture)
20 const captionfileAttach = args.mimeType ? [ captionfile, { contentType: args.mimeType } ] : captionfile
21
17 return makeUploadRequest({ 22 return makeUploadRequest({
18 method: 'PUT', 23 method: 'PUT',
19 url: args.url, 24 url: args.url,
@@ -21,9 +26,9 @@ function createVideoCaption (args: {
21 token: args.accessToken, 26 token: args.accessToken,
22 fields: {}, 27 fields: {},
23 attaches: { 28 attaches: {
24 captionfile: buildAbsoluteFixturePath(args.fixture) 29 captionfile: captionfileAttach
25 }, 30 },
26 statusCodeExpected: 204 31 statusCodeExpected: args.statusCodeExpected || 204
27 }) 32 })
28} 33}
29 34