diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-02-21 21:35:59 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-02-26 20:01:26 +0100 |
commit | 9e167724f7e933f41d9ea2e1c31772bf4c560a28 (patch) | |
tree | 093cb7c1b088f35aaf847f859a313a121c8cd233 /server/helpers | |
parent | 0150b17e51df3e9fad8a59133d828c68f8ba672b (diff) | |
download | PeerTube-9e167724f7e933f41d9ea2e1c31772bf4c560a28.tar.gz PeerTube-9e167724f7e933f41d9ea2e1c31772bf4c560a28.tar.zst PeerTube-9e167724f7e933f41d9ea2e1c31772bf4c560a28.zip |
Server: make a basic "quick and dirty update" for videos
This system will be useful to to update some int video attributes
(likes, dislikes, views...)
The classic system is not used because we need some optimization for
scaling
Diffstat (limited to 'server/helpers')
-rw-r--r-- | server/helpers/custom-validators/remote/videos.js | 25 | ||||
-rw-r--r-- | server/helpers/custom-validators/videos.js | 17 | ||||
-rw-r--r-- | server/helpers/requests.js | 2 |
3 files changed, 39 insertions, 5 deletions
diff --git a/server/helpers/custom-validators/remote/videos.js b/server/helpers/custom-validators/remote/videos.js index ee68ebc10..2e9cf822e 100644 --- a/server/helpers/custom-validators/remote/videos.js +++ b/server/helpers/custom-validators/remote/videos.js | |||
@@ -1,5 +1,7 @@ | |||
1 | 'use strict' | 1 | 'use strict' |
2 | 2 | ||
3 | const has = require('lodash/has') | ||
4 | |||
3 | const constants = require('../../../initializers/constants') | 5 | const constants = require('../../../initializers/constants') |
4 | const videosValidators = require('../videos') | 6 | const videosValidators = require('../videos') |
5 | const miscValidators = require('../misc') | 7 | const miscValidators = require('../misc') |
@@ -7,7 +9,8 @@ const miscValidators = require('../misc') | |||
7 | const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS] | 9 | const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS] |
8 | 10 | ||
9 | const remoteVideosValidators = { | 11 | const remoteVideosValidators = { |
10 | isEachRemoteRequestVideosValid | 12 | isEachRemoteRequestVideosValid, |
13 | isEachRemoteRequestVideosQaduValid | ||
11 | } | 14 | } |
12 | 15 | ||
13 | function isEachRemoteRequestVideosValid (requests) { | 16 | function isEachRemoteRequestVideosValid (requests) { |
@@ -16,13 +19,13 @@ function isEachRemoteRequestVideosValid (requests) { | |||
16 | const video = request.data | 19 | const video = request.data |
17 | return ( | 20 | return ( |
18 | isRequestTypeAddValid(request.type) && | 21 | isRequestTypeAddValid(request.type) && |
19 | isCommonVideoAttrbiutesValid(video) && | 22 | isCommonVideoAttributesValid(video) && |
20 | videosValidators.isVideoAuthorValid(video.author) && | 23 | videosValidators.isVideoAuthorValid(video.author) && |
21 | videosValidators.isVideoThumbnailDataValid(video.thumbnailData) | 24 | videosValidators.isVideoThumbnailDataValid(video.thumbnailData) |
22 | ) || | 25 | ) || |
23 | ( | 26 | ( |
24 | isRequestTypeUpdateValid(request.type) && | 27 | isRequestTypeUpdateValid(request.type) && |
25 | isCommonVideoAttrbiutesValid(video) | 28 | isCommonVideoAttributesValid(video) |
26 | ) || | 29 | ) || |
27 | ( | 30 | ( |
28 | isRequestTypeRemoveValid(request.type) && | 31 | isRequestTypeRemoveValid(request.type) && |
@@ -37,13 +40,27 @@ function isEachRemoteRequestVideosValid (requests) { | |||
37 | }) | 40 | }) |
38 | } | 41 | } |
39 | 42 | ||
43 | function isEachRemoteRequestVideosQaduValid (requests) { | ||
44 | return miscValidators.isArray(requests) && | ||
45 | requests.every(function (request) { | ||
46 | const video = request.data | ||
47 | |||
48 | return ( | ||
49 | videosValidators.isVideoRemoteIdValid(video.remoteId) && | ||
50 | (has(video, 'views') === false || videosValidators.isVideoViewsValid) && | ||
51 | (has(video, 'likes') === false || videosValidators.isVideoLikesValid) && | ||
52 | (has(video, 'dislikes') === false || videosValidators.isVideoDislikesValid) | ||
53 | ) | ||
54 | }) | ||
55 | } | ||
56 | |||
40 | // --------------------------------------------------------------------------- | 57 | // --------------------------------------------------------------------------- |
41 | 58 | ||
42 | module.exports = remoteVideosValidators | 59 | module.exports = remoteVideosValidators |
43 | 60 | ||
44 | // --------------------------------------------------------------------------- | 61 | // --------------------------------------------------------------------------- |
45 | 62 | ||
46 | function isCommonVideoAttrbiutesValid (video) { | 63 | function isCommonVideoAttributesValid (video) { |
47 | return videosValidators.isVideoDateValid(video.createdAt) && | 64 | return videosValidators.isVideoDateValid(video.createdAt) && |
48 | videosValidators.isVideoDateValid(video.updatedAt) && | 65 | videosValidators.isVideoDateValid(video.updatedAt) && |
49 | videosValidators.isVideoDescriptionValid(video.description) && | 66 | videosValidators.isVideoDescriptionValid(video.description) && |
diff --git a/server/helpers/custom-validators/videos.js b/server/helpers/custom-validators/videos.js index e2d2c8e6d..1d844118b 100644 --- a/server/helpers/custom-validators/videos.js +++ b/server/helpers/custom-validators/videos.js | |||
@@ -22,7 +22,10 @@ const videosValidators = { | |||
22 | isVideoRemoteIdValid, | 22 | isVideoRemoteIdValid, |
23 | isVideoAbuseReasonValid, | 23 | isVideoAbuseReasonValid, |
24 | isVideoAbuseReporterUsernameValid, | 24 | isVideoAbuseReporterUsernameValid, |
25 | isVideoFile | 25 | isVideoFile, |
26 | isVideoViewsValid, | ||
27 | isVideoLikesValid, | ||
28 | isVideoDislikesValid | ||
26 | } | 29 | } |
27 | 30 | ||
28 | function isVideoAuthorValid (value) { | 31 | function isVideoAuthorValid (value) { |
@@ -82,6 +85,18 @@ function isVideoAbuseReporterUsernameValid (value) { | |||
82 | return usersValidators.isUserUsernameValid(value) | 85 | return usersValidators.isUserUsernameValid(value) |
83 | } | 86 | } |
84 | 87 | ||
88 | function isVideoViewsValid (value) { | ||
89 | return validator.isInt(value, { min: 0 }) | ||
90 | } | ||
91 | |||
92 | function isVideoLikesValid (value) { | ||
93 | return validator.isInt(value, { min: 0 }) | ||
94 | } | ||
95 | |||
96 | function isVideoDislikesValid (value) { | ||
97 | return validator.isInt(value, { min: 0 }) | ||
98 | } | ||
99 | |||
85 | function isVideoFile (value, files) { | 100 | function isVideoFile (value, files) { |
86 | // Should have files | 101 | // Should have files |
87 | if (!files) return false | 102 | if (!files) return false |
diff --git a/server/helpers/requests.js b/server/helpers/requests.js index 095b95e1c..427864117 100644 --- a/server/helpers/requests.js +++ b/server/helpers/requests.js | |||
@@ -58,6 +58,8 @@ function makeSecureRequest (params, callback) { | |||
58 | requestParams.json.data = params.data | 58 | requestParams.json.data = params.data |
59 | } | 59 | } |
60 | 60 | ||
61 | console.log(requestParams.json.data) | ||
62 | |||
61 | request.post(requestParams, callback) | 63 | request.post(requestParams, callback) |
62 | } | 64 | } |
63 | 65 | ||