aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/helpers/custom-validators/accounts.ts5
-rw-r--r--server/helpers/custom-validators/videos.ts14
-rw-r--r--server/middlewares/servers.ts18
-rw-r--r--server/middlewares/validators/video-channels.ts19
-rw-r--r--server/models/server/server.ts2
-rw-r--r--server/models/video/video-file.ts16
-rw-r--r--server/tests/utils/video-abuses.ts29
-rw-r--r--server/tests/utils/videos.ts14
8 files changed, 27 insertions, 90 deletions
diff --git a/server/helpers/custom-validators/accounts.ts b/server/helpers/custom-validators/accounts.ts
index 83540e545..fe0fc650a 100644
--- a/server/helpers/custom-validators/accounts.ts
+++ b/server/helpers/custom-validators/accounts.ts
@@ -1,14 +1,11 @@
1import * as Promise from 'bluebird' 1import * as Promise from 'bluebird'
2import * as validator from 'validator'
3import * as express from 'express' 2import * as express from 'express'
4import 'express-validator' 3import 'express-validator'
5 4import * as validator from 'validator'
6import { database as db } from '../../initializers' 5import { database as db } from '../../initializers'
7import { AccountInstance } from '../../models' 6import { AccountInstance } from '../../models'
8import { logger } from '../logger' 7import { logger } from '../logger'
9
10import { isUserUsernameValid } from './users' 8import { isUserUsernameValid } from './users'
11import { isHostValid } from './servers'
12 9
13function isAccountNameValid (value: string) { 10function isAccountNameValid (value: string) {
14 return isUserUsernameValid(value) 11 return isUserUsernameValid(value)
diff --git a/server/helpers/custom-validators/videos.ts b/server/helpers/custom-validators/videos.ts
index c893d2c7c..205d8c62f 100644
--- a/server/helpers/custom-validators/videos.ts
+++ b/server/helpers/custom-validators/videos.ts
@@ -90,12 +90,20 @@ function isVideoFile (files: { [ fieldname: string ]: Express.Multer.File[] } |
90 return new RegExp('^video/(webm|mp4|ogg)$', 'i').test(file.mimetype) 90 return new RegExp('^video/(webm|mp4|ogg)$', 'i').test(file.mimetype)
91} 91}
92 92
93function isVideoPrivacyValid (value: string) {
94 return VIDEO_PRIVACIES[value] !== undefined
95}
96
93function isVideoFileInfoHashValid (value: string) { 97function isVideoFileInfoHashValid (value: string) {
94 return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.INFO_HASH) 98 return exists(value) && validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.INFO_HASH)
95} 99}
96 100
97function isVideoPrivacyValid (value: string) { 101function isVideoFileResolutionValid (value: string) {
98 return VIDEO_PRIVACIES[value] !== undefined 102 return exists(value) && validator.isInt(value + '')
103}
104
105function isVideoFileSizeValid (value: string) {
106 return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.FILE_SIZE)
99} 107}
100 108
101function checkVideoExists (id: string, res: Response, callback: () => void) { 109function checkVideoExists (id: string, res: Response, callback: () => void) {
@@ -142,5 +150,7 @@ export {
142 isVideoTagValid, 150 isVideoTagValid,
143 isVideoUrlValid, 151 isVideoUrlValid,
144 isVideoPrivacyValid, 152 isVideoPrivacyValid,
153 isVideoFileResolutionValid,
154 isVideoFileSizeValid,
145 checkVideoExists 155 checkVideoExists
146} 156}
diff --git a/server/middlewares/servers.ts b/server/middlewares/servers.ts
index eaf9aa144..488f9c368 100644
--- a/server/middlewares/servers.ts
+++ b/server/middlewares/servers.ts
@@ -20,26 +20,10 @@ function setBodyHostsPort (req: express.Request, res: express.Response, next: ex
20 return next() 20 return next()
21} 21}
22 22
23function setBodyHostPort (req: express.Request, res: express.Response, next: express.NextFunction) {
24 if (!req.body.host) return next()
25
26 const hostWithPort = getHostWithPort(req.body.host)
27
28 // Problem with the url parsing?
29 if (hostWithPort === null) {
30 return res.sendStatus(500)
31 }
32
33 req.body.host = hostWithPort
34
35 return next()
36}
37
38// --------------------------------------------------------------------------- 23// ---------------------------------------------------------------------------
39 24
40export { 25export {
41 setBodyHostsPort, 26 setBodyHostsPort
42 setBodyHostPort
43} 27}
44 28
45// --------------------------------------------------------------------------- 29// ---------------------------------------------------------------------------
diff --git a/server/middlewares/validators/video-channels.ts b/server/middlewares/validators/video-channels.ts
index 0326e05b9..c6fd3b59d 100644
--- a/server/middlewares/validators/video-channels.ts
+++ b/server/middlewares/validators/video-channels.ts
@@ -1,18 +1,13 @@
1import { body, param } from 'express-validator/check'
2import * as express from 'express' 1import * as express from 'express'
3 2import { body, param } from 'express-validator/check'
4import { checkErrors } from './utils' 3import { UserRight } from '../../../shared'
4import { checkVideoAccountExists } from '../../helpers/custom-validators/accounts'
5import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../../helpers/custom-validators/video-channels'
6import { checkVideoChannelExists, isIdOrUUIDValid } from '../../helpers/index'
7import { logger } from '../../helpers/logger'
5import { database as db } from '../../initializers' 8import { database as db } from '../../initializers'
6import {
7 logger,
8 isIdOrUUIDValid,
9 isVideoChannelDescriptionValid,
10 isVideoChannelNameValid,
11 checkVideoChannelExists,
12 checkVideoAccountExists
13} from '../../helpers'
14import { UserInstance } from '../../models' 9import { UserInstance } from '../../models'
15import { UserRight } from '../../../shared' 10import { checkErrors } from './utils'
16 11
17const listVideoAccountChannelsValidator = [ 12const listVideoAccountChannelsValidator = [
18 param('accountId').custom(isIdOrUUIDValid).withMessage('Should have a valid account id'), 13 param('accountId').custom(isIdOrUUIDValid).withMessage('Should have a valid account id'),
diff --git a/server/models/server/server.ts b/server/models/server/server.ts
index 75cd5f929..fcd7be090 100644
--- a/server/models/server/server.ts
+++ b/server/models/server/server.ts
@@ -44,7 +44,7 @@ export default function (sequelize: Sequelize.Sequelize, DataTypes: Sequelize.Da
44 ) 44 )
45 45
46 const classMethods = [ 46 const classMethods = [
47 listBadServers 47 updateServersScoreAndRemoveBadOnes
48 ] 48 ]
49 addMethodsToModel(Server, classMethods) 49 addMethodsToModel(Server, classMethods)
50 50
diff --git a/server/models/video/video-file.ts b/server/models/video/video-file.ts
index ead7f3e03..600141994 100644
--- a/server/models/video/video-file.ts
+++ b/server/models/video/video-file.ts
@@ -1,18 +1,10 @@
1import * as Sequelize from 'sequelize'
2import { values } from 'lodash' 1import { values } from 'lodash'
3 2import * as Sequelize from 'sequelize'
4import { CONSTRAINTS_FIELDS } from '../../initializers' 3import { isVideoFileInfoHashValid, isVideoFileResolutionValid, isVideoFileSizeValid } from '../../helpers/custom-validators/videos'
5import { 4import { CONSTRAINTS_FIELDS } from '../../initializers/constants'
6 isVideoFileResolutionValid,
7 isVideoFileSizeValid,
8 isVideoFileInfoHashValid
9} from '../../helpers'
10 5
11import { addMethodsToModel } from '../utils' 6import { addMethodsToModel } from '../utils'
12import { 7import { VideoFileAttributes, VideoFileInstance } from './video-file-interface'
13 VideoFileInstance,
14 VideoFileAttributes
15} from './video-file-interface'
16 8
17let VideoFile: Sequelize.Model<VideoFileInstance, VideoFileAttributes> 9let VideoFile: Sequelize.Model<VideoFileInstance, VideoFileAttributes>
18 10
diff --git a/server/tests/utils/video-abuses.ts b/server/tests/utils/video-abuses.ts
index f7ee958d7..f00809234 100644
--- a/server/tests/utils/video-abuses.ts
+++ b/server/tests/utils/video-abuses.ts
@@ -23,36 +23,9 @@ function getVideoAbusesList (url: string, token: string) {
23 .expect('Content-Type', /json/) 23 .expect('Content-Type', /json/)
24} 24}
25 25
26function getVideoAbusesListPagination (url: string, token: string, start: number, count: number) {
27 const path = '/api/v1/videos/abuse'
28
29 return request(url)
30 .get(path)
31 .query({ start: start })
32 .query({ count: count })
33 .set('Accept', 'application/json')
34 .set('Authorization', 'Bearer ' + token)
35 .expect(200)
36 .expect('Content-Type', /json/)
37}
38
39function getVideoAbusesListSort (url: string, token: string, sort: string) {
40 const path = '/api/v1/videos/abuse'
41
42 return request(url)
43 .get(path)
44 .query({ sort: sort })
45 .set('Accept', 'application/json')
46 .set('Authorization', 'Bearer ' + token)
47 .expect(200)
48 .expect('Content-Type', /json/)
49}
50
51// --------------------------------------------------------------------------- 26// ---------------------------------------------------------------------------
52 27
53export { 28export {
54 reportVideoAbuse, 29 reportVideoAbuse,
55 getVideoAbusesList, 30 getVideoAbusesList
56 getVideoAbusesListPagination,
57 getVideoAbusesListSort
58} 31}
diff --git a/server/tests/utils/videos.ts b/server/tests/utils/videos.ts
index d4d5faf0a..dababe924 100644
--- a/server/tests/utils/videos.ts
+++ b/server/tests/utils/videos.ts
@@ -46,19 +46,6 @@ function getVideoPrivacies (url: string) {
46 return makeGetRequest(url, path) 46 return makeGetRequest(url, path)
47} 47}
48 48
49function getAllVideosListBy (url: string) {
50 const path = '/api/v1/videos'
51
52 return request(url)
53 .get(path)
54 .query({ sort: 'createdAt' })
55 .query({ start: 0 })
56 .query({ count: 10000 })
57 .set('Accept', 'application/json')
58 .expect(200)
59 .expect('Content-Type', /json/)
60}
61
62function getVideo (url: string, id: number | string, expectedStatus = 200) { 49function getVideo (url: string, id: number | string, expectedStatus = 200) {
63 const path = '/api/v1/videos/' + id 50 const path = '/api/v1/videos/' + id
64 51
@@ -312,7 +299,6 @@ export {
312 getVideoLicences, 299 getVideoLicences,
313 getVideoPrivacies, 300 getVideoPrivacies,
314 getVideoLanguages, 301 getVideoLanguages,
315 getAllVideosListBy,
316 getMyVideos, 302 getMyVideos,
317 getVideo, 303 getVideo,
318 getVideoWithToken, 304 getVideoWithToken,