diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-01-04 20:59:23 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-01-04 21:05:13 +0100 |
commit | 55fa55a9be566cca2ba95322f2ae23b434aed62a (patch) | |
tree | f51ef35c120ce8a928917a659418079538cdb8dc /server/helpers | |
parent | a6fd2b30bf717eec14972a2175354781f5f43e77 (diff) | |
download | PeerTube-55fa55a9be566cca2ba95322f2ae23b434aed62a.tar.gz PeerTube-55fa55a9be566cca2ba95322f2ae23b434aed62a.tar.zst PeerTube-55fa55a9be566cca2ba95322f2ae23b434aed62a.zip |
Server: add video abuse support
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/custom-validators/index.js | 2 | ||||
-rw-r--r-- | server/helpers/custom-validators/remote/index.js | 11 | ||||
-rw-r--r-- | server/helpers/custom-validators/remote/videos.js | 74 | ||||
-rw-r--r-- | server/helpers/custom-validators/videos.js | 66 | ||||
-rw-r--r-- | server/helpers/utils.js | 16 |
5 files changed, 115 insertions, 54 deletions
diff --git a/server/helpers/custom-validators/index.js b/server/helpers/custom-validators/index.js index 96b5b20b9..9383e0304 100644 --- a/server/helpers/custom-validators/index.js +++ b/server/helpers/custom-validators/index.js | |||
@@ -2,12 +2,14 @@ | |||
2 | 2 | ||
3 | const miscValidators = require('./misc') | 3 | const miscValidators = require('./misc') |
4 | const podsValidators = require('./pods') | 4 | const podsValidators = require('./pods') |
5 | const remoteValidators = require('./remote') | ||
5 | const usersValidators = require('./users') | 6 | const usersValidators = require('./users') |
6 | const videosValidators = require('./videos') | 7 | const videosValidators = require('./videos') |
7 | 8 | ||
8 | const validators = { | 9 | const validators = { |
9 | misc: miscValidators, | 10 | misc: miscValidators, |
10 | pods: podsValidators, | 11 | pods: podsValidators, |
12 | remote: remoteValidators, | ||
11 | users: usersValidators, | 13 | users: usersValidators, |
12 | videos: videosValidators | 14 | videos: videosValidators |
13 | } | 15 | } |
diff --git a/server/helpers/custom-validators/remote/index.js b/server/helpers/custom-validators/remote/index.js new file mode 100644 index 000000000..1939a95f4 --- /dev/null +++ b/server/helpers/custom-validators/remote/index.js | |||
@@ -0,0 +1,11 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const remoteVideosValidators = require('./videos') | ||
4 | |||
5 | const validators = { | ||
6 | videos: remoteVideosValidators | ||
7 | } | ||
8 | |||
9 | // --------------------------------------------------------------------------- | ||
10 | |||
11 | module.exports = validators | ||
diff --git a/server/helpers/custom-validators/remote/videos.js b/server/helpers/custom-validators/remote/videos.js new file mode 100644 index 000000000..c3ca00e1c --- /dev/null +++ b/server/helpers/custom-validators/remote/videos.js | |||
@@ -0,0 +1,74 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const videosValidators = require('../videos') | ||
4 | const miscValidators = require('../misc') | ||
5 | |||
6 | const remoteVideosValidators = { | ||
7 | isEachRemoteRequestVideosValid | ||
8 | } | ||
9 | |||
10 | function isEachRemoteRequestVideosValid (requests) { | ||
11 | return miscValidators.isArray(requests) && | ||
12 | requests.every(function (request) { | ||
13 | const video = request.data | ||
14 | return ( | ||
15 | isRequestTypeAddValid(request.type) && | ||
16 | videosValidators.isVideoAuthorValid(video.author) && | ||
17 | videosValidators.isVideoDateValid(video.createdAt) && | ||
18 | videosValidators.isVideoDateValid(video.updatedAt) && | ||
19 | videosValidators.isVideoDescriptionValid(video.description) && | ||
20 | videosValidators.isVideoDurationValid(video.duration) && | ||
21 | videosValidators.isVideoInfoHashValid(video.infoHash) && | ||
22 | videosValidators.isVideoNameValid(video.name) && | ||
23 | videosValidators.isVideoTagsValid(video.tags) && | ||
24 | videosValidators.isVideoThumbnailDataValid(video.thumbnailData) && | ||
25 | videosValidators.isVideoRemoteIdValid(video.remoteId) && | ||
26 | videosValidators.isVideoExtnameValid(video.extname) | ||
27 | ) || | ||
28 | ( | ||
29 | isRequestTypeUpdateValid(request.type) && | ||
30 | videosValidators.isVideoDateValid(video.createdAt) && | ||
31 | videosValidators.isVideoDateValid(video.updatedAt) && | ||
32 | videosValidators.isVideoDescriptionValid(video.description) && | ||
33 | videosValidators.isVideoDurationValid(video.duration) && | ||
34 | videosValidators.isVideoInfoHashValid(video.infoHash) && | ||
35 | videosValidators.isVideoNameValid(video.name) && | ||
36 | videosValidators.isVideoTagsValid(video.tags) && | ||
37 | videosValidators.isVideoRemoteIdValid(video.remoteId) && | ||
38 | videosValidators.isVideoExtnameValid(video.extname) | ||
39 | ) || | ||
40 | ( | ||
41 | isRequestTypeRemoveValid(request.type) && | ||
42 | videosValidators.isVideoNameValid(video.name) && | ||
43 | videosValidators.isVideoRemoteIdValid(video.remoteId) | ||
44 | ) || | ||
45 | ( | ||
46 | isRequestTypeReportAbuseValid(request.type) && | ||
47 | videosValidators.isVideoRemoteIdValid(request.data.videoRemoteId) && | ||
48 | videosValidators.isVideoAbuseReasonValid(request.data.reportReason) && | ||
49 | videosValidators.isVideoAbuseReporterUsernameValid(request.data.reporterUsername) | ||
50 | ) | ||
51 | }) | ||
52 | } | ||
53 | |||
54 | // --------------------------------------------------------------------------- | ||
55 | |||
56 | module.exports = remoteVideosValidators | ||
57 | |||
58 | // --------------------------------------------------------------------------- | ||
59 | |||
60 | function isRequestTypeAddValid (value) { | ||
61 | return value === 'add' | ||
62 | } | ||
63 | |||
64 | function isRequestTypeUpdateValid (value) { | ||
65 | return value === 'update' | ||
66 | } | ||
67 | |||
68 | function isRequestTypeRemoveValid (value) { | ||
69 | return value === 'remove' | ||
70 | } | ||
71 | |||
72 | function isRequestTypeReportAbuseValid (value) { | ||
73 | return value === 'report-abuse' | ||
74 | } | ||
diff --git a/server/helpers/custom-validators/videos.js b/server/helpers/custom-validators/videos.js index 8448386d9..7f727854d 100644 --- a/server/helpers/custom-validators/videos.js +++ b/server/helpers/custom-validators/videos.js | |||
@@ -6,9 +6,9 @@ const constants = require('../../initializers/constants') | |||
6 | const usersValidators = require('./users') | 6 | const usersValidators = require('./users') |
7 | const miscValidators = require('./misc') | 7 | const miscValidators = require('./misc') |
8 | const VIDEOS_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.VIDEOS | 8 | const VIDEOS_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.VIDEOS |
9 | const VIDEO_ABUSES_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.VIDEO_ABUSES | ||
9 | 10 | ||
10 | const videosValidators = { | 11 | const videosValidators = { |
11 | isEachRemoteVideosValid, | ||
12 | isVideoAuthorValid, | 12 | isVideoAuthorValid, |
13 | isVideoDateValid, | 13 | isVideoDateValid, |
14 | isVideoDescriptionValid, | 14 | isVideoDescriptionValid, |
@@ -17,45 +17,11 @@ const videosValidators = { | |||
17 | isVideoNameValid, | 17 | isVideoNameValid, |
18 | isVideoTagsValid, | 18 | isVideoTagsValid, |
19 | isVideoThumbnailValid, | 19 | isVideoThumbnailValid, |
20 | isVideoThumbnailDataValid | 20 | isVideoThumbnailDataValid, |
21 | } | 21 | isVideoExtnameValid, |
22 | 22 | isVideoRemoteIdValid, | |
23 | function isEachRemoteVideosValid (requests) { | 23 | isVideoAbuseReasonValid, |
24 | return miscValidators.isArray(requests) && | 24 | isVideoAbuseReporterUsernameValid |
25 | requests.every(function (request) { | ||
26 | const video = request.data | ||
27 | return ( | ||
28 | isRequestTypeAddValid(request.type) && | ||
29 | isVideoAuthorValid(video.author) && | ||
30 | isVideoDateValid(video.createdAt) && | ||
31 | isVideoDateValid(video.updatedAt) && | ||
32 | isVideoDescriptionValid(video.description) && | ||
33 | isVideoDurationValid(video.duration) && | ||
34 | isVideoInfoHashValid(video.infoHash) && | ||
35 | isVideoNameValid(video.name) && | ||
36 | isVideoTagsValid(video.tags) && | ||
37 | isVideoThumbnailDataValid(video.thumbnailData) && | ||
38 | isVideoRemoteIdValid(video.remoteId) && | ||
39 | isVideoExtnameValid(video.extname) | ||
40 | ) || | ||
41 | ( | ||
42 | isRequestTypeUpdateValid(request.type) && | ||
43 | isVideoDateValid(video.createdAt) && | ||
44 | isVideoDateValid(video.updatedAt) && | ||
45 | isVideoDescriptionValid(video.description) && | ||
46 | isVideoDurationValid(video.duration) && | ||
47 | isVideoInfoHashValid(video.infoHash) && | ||
48 | isVideoNameValid(video.name) && | ||
49 | isVideoTagsValid(video.tags) && | ||
50 | isVideoRemoteIdValid(video.remoteId) && | ||
51 | isVideoExtnameValid(video.extname) | ||
52 | ) || | ||
53 | ( | ||
54 | isRequestTypeRemoveValid(request.type) && | ||
55 | isVideoNameValid(video.name) && | ||
56 | isVideoRemoteIdValid(video.remoteId) | ||
57 | ) | ||
58 | }) | ||
59 | } | 25 | } |
60 | 26 | ||
61 | function isVideoAuthorValid (value) { | 27 | function isVideoAuthorValid (value) { |
@@ -107,20 +73,14 @@ function isVideoRemoteIdValid (value) { | |||
107 | return validator.isUUID(value, 4) | 73 | return validator.isUUID(value, 4) |
108 | } | 74 | } |
109 | 75 | ||
110 | // --------------------------------------------------------------------------- | 76 | function isVideoAbuseReasonValid (value) { |
111 | 77 | return validator.isLength(value, VIDEO_ABUSES_CONSTRAINTS_FIELDS.REASON) | |
112 | module.exports = videosValidators | ||
113 | |||
114 | // --------------------------------------------------------------------------- | ||
115 | |||
116 | function isRequestTypeAddValid (value) { | ||
117 | return value === 'add' | ||
118 | } | 78 | } |
119 | 79 | ||
120 | function isRequestTypeUpdateValid (value) { | 80 | function isVideoAbuseReporterUsernameValid (value) { |
121 | return value === 'update' | 81 | return usersValidators.isUserUsernameValid(value) |
122 | } | 82 | } |
123 | 83 | ||
124 | function isRequestTypeRemoveValid (value) { | 84 | // --------------------------------------------------------------------------- |
125 | return value === 'remove' | 85 | |
126 | } | 86 | module.exports = videosValidators |
diff --git a/server/helpers/utils.js b/server/helpers/utils.js index 7e0c9823c..9f4b14582 100644 --- a/server/helpers/utils.js +++ b/server/helpers/utils.js | |||
@@ -8,7 +8,8 @@ const utils = { | |||
8 | badRequest, | 8 | badRequest, |
9 | cleanForExit, | 9 | cleanForExit, |
10 | generateRandomString, | 10 | generateRandomString, |
11 | isTestInstance | 11 | isTestInstance, |
12 | getFormatedObjects | ||
12 | } | 13 | } |
13 | 14 | ||
14 | function badRequest (req, res, next) { | 15 | function badRequest (req, res, next) { |
@@ -32,6 +33,19 @@ function isTestInstance () { | |||
32 | return (process.env.NODE_ENV === 'test') | 33 | return (process.env.NODE_ENV === 'test') |
33 | } | 34 | } |
34 | 35 | ||
36 | function getFormatedObjects (objects, objectsTotal) { | ||
37 | const formatedObjects = [] | ||
38 | |||
39 | objects.forEach(function (object) { | ||
40 | formatedObjects.push(object.toFormatedJSON()) | ||
41 | }) | ||
42 | |||
43 | return { | ||
44 | total: objectsTotal, | ||
45 | data: formatedObjects | ||
46 | } | ||
47 | } | ||
48 | |||
35 | // --------------------------------------------------------------------------- | 49 | // --------------------------------------------------------------------------- |
36 | 50 | ||
37 | module.exports = utils | 51 | module.exports = utils |