aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/controllers/api/videos.js6
-rw-r--r--server/helpers/custom-validators/remote/videos.js45
-rw-r--r--server/lib/friends.js10
3 files changed, 29 insertions, 32 deletions
diff --git a/server/controllers/api/videos.js b/server/controllers/api/videos.js
index 75a661bcc..c936105e7 100644
--- a/server/controllers/api/videos.js
+++ b/server/controllers/api/videos.js
@@ -389,11 +389,7 @@ function reportVideoAbuse (req, res, finalCallback) {
389 389
390 waterfall([ 390 waterfall([
391 391
392 function startTransaction (callback) { 392 databaseUtils.startSerializableTransaction,
393 db.sequelize.transaction().asCallback(function (err, t) {
394 return callback(err, t)
395 })
396 },
397 393
398 function createAbuse (t, callback) { 394 function createAbuse (t, callback) {
399 db.VideoAbuse.create(abuse).asCallback(function (err, abuse) { 395 db.VideoAbuse.create(abuse).asCallback(function (err, abuse) {
diff --git a/server/helpers/custom-validators/remote/videos.js b/server/helpers/custom-validators/remote/videos.js
index 7c27b9dbb..ee68ebc10 100644
--- a/server/helpers/custom-validators/remote/videos.js
+++ b/server/helpers/custom-validators/remote/videos.js
@@ -1,8 +1,11 @@
1'use strict' 1'use strict'
2 2
3const constants = require('../../../initializers/constants')
3const videosValidators = require('../videos') 4const videosValidators = require('../videos')
4const miscValidators = require('../misc') 5const miscValidators = require('../misc')
5 6
7const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS]
8
6const remoteVideosValidators = { 9const remoteVideosValidators = {
7 isEachRemoteRequestVideosValid 10 isEachRemoteRequestVideosValid
8} 11}
@@ -13,29 +16,13 @@ function isEachRemoteRequestVideosValid (requests) {
13 const video = request.data 16 const video = request.data
14 return ( 17 return (
15 isRequestTypeAddValid(request.type) && 18 isRequestTypeAddValid(request.type) &&
19 isCommonVideoAttrbiutesValid(video) &&
16 videosValidators.isVideoAuthorValid(video.author) && 20 videosValidators.isVideoAuthorValid(video.author) &&
17 videosValidators.isVideoDateValid(video.createdAt) && 21 videosValidators.isVideoThumbnailDataValid(video.thumbnailData)
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 ) || 22 ) ||
28 ( 23 (
29 isRequestTypeUpdateValid(request.type) && 24 isRequestTypeUpdateValid(request.type) &&
30 videosValidators.isVideoDateValid(video.createdAt) && 25 isCommonVideoAttrbiutesValid(video)
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 ) || 26 ) ||
40 ( 27 (
41 isRequestTypeRemoveValid(request.type) && 28 isRequestTypeRemoveValid(request.type) &&
@@ -56,18 +43,30 @@ module.exports = remoteVideosValidators
56 43
57// --------------------------------------------------------------------------- 44// ---------------------------------------------------------------------------
58 45
46function isCommonVideoAttrbiutesValid (video) {
47 return videosValidators.isVideoDateValid(video.createdAt) &&
48 videosValidators.isVideoDateValid(video.updatedAt) &&
49 videosValidators.isVideoDescriptionValid(video.description) &&
50 videosValidators.isVideoDurationValid(video.duration) &&
51 videosValidators.isVideoInfoHashValid(video.infoHash) &&
52 videosValidators.isVideoNameValid(video.name) &&
53 videosValidators.isVideoTagsValid(video.tags) &&
54 videosValidators.isVideoRemoteIdValid(video.remoteId) &&
55 videosValidators.isVideoExtnameValid(video.extname)
56}
57
59function isRequestTypeAddValid (value) { 58function isRequestTypeAddValid (value) {
60 return value === 'add' 59 return value === ENDPOINT_ACTIONS.ADD
61} 60}
62 61
63function isRequestTypeUpdateValid (value) { 62function isRequestTypeUpdateValid (value) {
64 return value === 'update' 63 return value === ENDPOINT_ACTIONS.UPDATE
65} 64}
66 65
67function isRequestTypeRemoveValid (value) { 66function isRequestTypeRemoveValid (value) {
68 return value === 'remove' 67 return value === ENDPOINT_ACTIONS.REMOVE
69} 68}
70 69
71function isRequestTypeReportAbuseValid (value) { 70function isRequestTypeReportAbuseValid (value) {
72 return value === 'report-abuse' 71 return value === ENDPOINT_ACTIONS.REPORT_ABUSE
73} 72}
diff --git a/server/lib/friends.js b/server/lib/friends.js
index f0575ff2f..f634aedbb 100644
--- a/server/lib/friends.js
+++ b/server/lib/friends.js
@@ -12,6 +12,8 @@ const db = require('../initializers/database')
12const logger = require('../helpers/logger') 12const logger = require('../helpers/logger')
13const requests = require('../helpers/requests') 13const requests = require('../helpers/requests')
14 14
15const ENDPOINT_ACTIONS = constants.REQUEST_ENDPOINT_ACTIONS[constants.REQUEST_ENDPOINTS.VIDEOS]
16
15const friends = { 17const friends = {
16 addVideoToFriends, 18 addVideoToFriends,
17 updateVideoToFriends, 19 updateVideoToFriends,
@@ -26,7 +28,7 @@ const friends = {
26 28
27function addVideoToFriends (videoData, transaction, callback) { 29function addVideoToFriends (videoData, transaction, callback) {
28 const options = { 30 const options = {
29 type: 'add', 31 type: ENDPOINT_ACTIONS.ADD,
30 endpoint: constants.REQUEST_ENDPOINTS.VIDEOS, 32 endpoint: constants.REQUEST_ENDPOINTS.VIDEOS,
31 data: videoData, 33 data: videoData,
32 transaction 34 transaction
@@ -36,7 +38,7 @@ function addVideoToFriends (videoData, transaction, callback) {
36 38
37function updateVideoToFriends (videoData, transaction, callback) { 39function updateVideoToFriends (videoData, transaction, callback) {
38 const options = { 40 const options = {
39 type: 'update', 41 type: ENDPOINT_ACTIONS.UPDATE,
40 endpoint: constants.REQUEST_ENDPOINTS.VIDEOS, 42 endpoint: constants.REQUEST_ENDPOINTS.VIDEOS,
41 data: videoData, 43 data: videoData,
42 transaction 44 transaction
@@ -46,7 +48,7 @@ function updateVideoToFriends (videoData, transaction, callback) {
46 48
47function removeVideoToFriends (videoParams) { 49function removeVideoToFriends (videoParams) {
48 const options = { 50 const options = {
49 type: 'remove', 51 type: ENDPOINT_ACTIONS.REMOVE,
50 endpoint: constants.REQUEST_ENDPOINTS.VIDEOS, 52 endpoint: constants.REQUEST_ENDPOINTS.VIDEOS,
51 data: videoParams 53 data: videoParams
52 } 54 }
@@ -55,7 +57,7 @@ function removeVideoToFriends (videoParams) {
55 57
56function reportAbuseVideoToFriend (reportData, video) { 58function reportAbuseVideoToFriend (reportData, video) {
57 const options = { 59 const options = {
58 type: 'report-abuse', 60 type: ENDPOINT_ACTIONS.REPORT_ABUSE,
59 endpoint: constants.REQUEST_ENDPOINTS.VIDEOS, 61 endpoint: constants.REQUEST_ENDPOINTS.VIDEOS,
60 data: reportData, 62 data: reportData,
61 toIds: [ video.Author.podId ] 63 toIds: [ video.Author.podId ]