aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/custom-validators/remote
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-02-21 21:35:59 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-02-26 20:01:26 +0100
commit9e167724f7e933f41d9ea2e1c31772bf4c560a28 (patch)
tree093cb7c1b088f35aaf847f859a313a121c8cd233 /server/helpers/custom-validators/remote
parent0150b17e51df3e9fad8a59133d828c68f8ba672b (diff)
downloadPeerTube-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/custom-validators/remote')
-rw-r--r--server/helpers/custom-validators/remote/videos.js25
1 files changed, 21 insertions, 4 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
3const has = require('lodash/has')
4
3const constants = require('../../../initializers/constants') 5const constants = require('../../../initializers/constants')
4const videosValidators = require('../videos') 6const videosValidators = require('../videos')
5const miscValidators = require('../misc') 7const miscValidators = require('../misc')
@@ -7,7 +9,8 @@ const miscValidators = require('../misc')
7const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS] 9const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS]
8 10
9const remoteVideosValidators = { 11const remoteVideosValidators = {
10 isEachRemoteRequestVideosValid 12 isEachRemoteRequestVideosValid,
13 isEachRemoteRequestVideosQaduValid
11} 14}
12 15
13function isEachRemoteRequestVideosValid (requests) { 16function 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
43function 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
42module.exports = remoteVideosValidators 59module.exports = remoteVideosValidators
43 60
44// --------------------------------------------------------------------------- 61// ---------------------------------------------------------------------------
45 62
46function isCommonVideoAttrbiutesValid (video) { 63function 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) &&