diff options
-rw-r--r-- | server/helpers/custom-validators/accounts.ts | 5 | ||||
-rw-r--r-- | server/helpers/custom-validators/videos.ts | 14 | ||||
-rw-r--r-- | server/middlewares/servers.ts | 18 | ||||
-rw-r--r-- | server/middlewares/validators/video-channels.ts | 19 | ||||
-rw-r--r-- | server/models/server/server.ts | 2 | ||||
-rw-r--r-- | server/models/video/video-file.ts | 16 | ||||
-rw-r--r-- | server/tests/utils/video-abuses.ts | 29 | ||||
-rw-r--r-- | server/tests/utils/videos.ts | 14 |
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 @@ | |||
1 | import * as Promise from 'bluebird' | 1 | import * as Promise from 'bluebird' |
2 | import * as validator from 'validator' | ||
3 | import * as express from 'express' | 2 | import * as express from 'express' |
4 | import 'express-validator' | 3 | import 'express-validator' |
5 | 4 | import * as validator from 'validator' | |
6 | import { database as db } from '../../initializers' | 5 | import { database as db } from '../../initializers' |
7 | import { AccountInstance } from '../../models' | 6 | import { AccountInstance } from '../../models' |
8 | import { logger } from '../logger' | 7 | import { logger } from '../logger' |
9 | |||
10 | import { isUserUsernameValid } from './users' | 8 | import { isUserUsernameValid } from './users' |
11 | import { isHostValid } from './servers' | ||
12 | 9 | ||
13 | function isAccountNameValid (value: string) { | 10 | function 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 | ||
93 | function isVideoPrivacyValid (value: string) { | ||
94 | return VIDEO_PRIVACIES[value] !== undefined | ||
95 | } | ||
96 | |||
93 | function isVideoFileInfoHashValid (value: string) { | 97 | function 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 | ||
97 | function isVideoPrivacyValid (value: string) { | 101 | function isVideoFileResolutionValid (value: string) { |
98 | return VIDEO_PRIVACIES[value] !== undefined | 102 | return exists(value) && validator.isInt(value + '') |
103 | } | ||
104 | |||
105 | function isVideoFileSizeValid (value: string) { | ||
106 | return exists(value) && validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.FILE_SIZE) | ||
99 | } | 107 | } |
100 | 108 | ||
101 | function checkVideoExists (id: string, res: Response, callback: () => void) { | 109 | function 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 | ||
23 | function 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 | ||
40 | export { | 25 | export { |
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 @@ | |||
1 | import { body, param } from 'express-validator/check' | ||
2 | import * as express from 'express' | 1 | import * as express from 'express' |
3 | 2 | import { body, param } from 'express-validator/check' | |
4 | import { checkErrors } from './utils' | 3 | import { UserRight } from '../../../shared' |
4 | import { checkVideoAccountExists } from '../../helpers/custom-validators/accounts' | ||
5 | import { isVideoChannelDescriptionValid, isVideoChannelNameValid } from '../../helpers/custom-validators/video-channels' | ||
6 | import { checkVideoChannelExists, isIdOrUUIDValid } from '../../helpers/index' | ||
7 | import { logger } from '../../helpers/logger' | ||
5 | import { database as db } from '../../initializers' | 8 | import { database as db } from '../../initializers' |
6 | import { | ||
7 | logger, | ||
8 | isIdOrUUIDValid, | ||
9 | isVideoChannelDescriptionValid, | ||
10 | isVideoChannelNameValid, | ||
11 | checkVideoChannelExists, | ||
12 | checkVideoAccountExists | ||
13 | } from '../../helpers' | ||
14 | import { UserInstance } from '../../models' | 9 | import { UserInstance } from '../../models' |
15 | import { UserRight } from '../../../shared' | 10 | import { checkErrors } from './utils' |
16 | 11 | ||
17 | const listVideoAccountChannelsValidator = [ | 12 | const 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 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | import { values } from 'lodash' | 1 | import { values } from 'lodash' |
3 | 2 | import * as Sequelize from 'sequelize' | |
4 | import { CONSTRAINTS_FIELDS } from '../../initializers' | 3 | import { isVideoFileInfoHashValid, isVideoFileResolutionValid, isVideoFileSizeValid } from '../../helpers/custom-validators/videos' |
5 | import { | 4 | import { CONSTRAINTS_FIELDS } from '../../initializers/constants' |
6 | isVideoFileResolutionValid, | ||
7 | isVideoFileSizeValid, | ||
8 | isVideoFileInfoHashValid | ||
9 | } from '../../helpers' | ||
10 | 5 | ||
11 | import { addMethodsToModel } from '../utils' | 6 | import { addMethodsToModel } from '../utils' |
12 | import { | 7 | import { VideoFileAttributes, VideoFileInstance } from './video-file-interface' |
13 | VideoFileInstance, | ||
14 | VideoFileAttributes | ||
15 | } from './video-file-interface' | ||
16 | 8 | ||
17 | let VideoFile: Sequelize.Model<VideoFileInstance, VideoFileAttributes> | 9 | let 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 | ||
26 | function 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 | |||
39 | function 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 | ||
53 | export { | 28 | export { |
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 | ||
49 | function 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 | |||
62 | function getVideo (url: string, id: number | string, expectedStatus = 200) { | 49 | function 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, |