From feb4bdfd9b46e87aadfa7c0d5338cde887d1f58c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Sun, 11 Dec 2016 21:50:51 +0100 Subject: First version with PostgreSQL --- server/helpers/custom-validators/videos.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'server/helpers/custom-validators') diff --git a/server/helpers/custom-validators/videos.js b/server/helpers/custom-validators/videos.js index 1a7753265..be8256a80 100644 --- a/server/helpers/custom-validators/videos.js +++ b/server/helpers/custom-validators/videos.js @@ -13,7 +13,7 @@ const videosValidators = { isVideoDateValid, isVideoDescriptionValid, isVideoDurationValid, - isVideoMagnetValid, + isVideoInfoHashValid, isVideoNameValid, isVideoPodHostValid, isVideoTagsValid, @@ -28,14 +28,15 @@ function isEachRemoteVideosValid (requests) { return ( isRequestTypeAddValid(request.type) && isVideoAuthorValid(video.author) && - isVideoDateValid(video.createdDate) && + isVideoDateValid(video.createdAt) && isVideoDescriptionValid(video.description) && isVideoDurationValid(video.duration) && - isVideoMagnetValid(video.magnet) && + isVideoInfoHashValid(video.infoHash) && isVideoNameValid(video.name) && isVideoTagsValid(video.tags) && isVideoThumbnail64Valid(video.thumbnailBase64) && - isVideoRemoteIdValid(video.remoteId) + isVideoRemoteIdValid(video.remoteId) && + isVideoExtnameValid(video.extname) ) || ( isRequestTypeRemoveValid(request.type) && @@ -61,8 +62,12 @@ function isVideoDurationValid (value) { return validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.DURATION) } -function isVideoMagnetValid (value) { - return validator.isLength(value.infoHash, VIDEOS_CONSTRAINTS_FIELDS.MAGNET.INFO_HASH) +function isVideoExtnameValid (value) { + return VIDEOS_CONSTRAINTS_FIELDS.EXTNAME.indexOf(value) !== -1 +} + +function isVideoInfoHashValid (value) { + return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.INFO_HASH) } function isVideoNameValid (value) { @@ -93,7 +98,7 @@ function isVideoThumbnail64Valid (value) { } function isVideoRemoteIdValid (value) { - return validator.isMongoId(value) + return validator.isUUID(value, 4) } // --------------------------------------------------------------------------- -- cgit v1.2.3 From 67bf9b96bbcd92b069fe86d9223fe0f8b9c6e677 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 28 Dec 2016 15:49:23 +0100 Subject: Server: add database field validations --- server/helpers/custom-validators/pods.js | 9 +++++++-- server/helpers/custom-validators/videos.js | 6 ------ 2 files changed, 7 insertions(+), 8 deletions(-) (limited to 'server/helpers/custom-validators') diff --git a/server/helpers/custom-validators/pods.js b/server/helpers/custom-validators/pods.js index 0154a2424..8bb3733ff 100644 --- a/server/helpers/custom-validators/pods.js +++ b/server/helpers/custom-validators/pods.js @@ -5,14 +5,19 @@ const validator = require('express-validator').validator const miscValidators = require('./misc') const podsValidators = { - isEachUniqueHostValid + isEachUniqueHostValid, + isHostValid +} + +function isHostValid (host) { + return validator.isURL(host) && host.split('://').length === 1 } function isEachUniqueHostValid (hosts) { return miscValidators.isArray(hosts) && hosts.length !== 0 && hosts.every(function (host) { - return validator.isURL(host) && host.split('://').length === 1 && hosts.indexOf(host) === hosts.lastIndexOf(host) + return isHostValid(host) && hosts.indexOf(host) === hosts.lastIndexOf(host) }) } diff --git a/server/helpers/custom-validators/videos.js b/server/helpers/custom-validators/videos.js index be8256a80..da857ba5f 100644 --- a/server/helpers/custom-validators/videos.js +++ b/server/helpers/custom-validators/videos.js @@ -15,7 +15,6 @@ const videosValidators = { isVideoDurationValid, isVideoInfoHashValid, isVideoNameValid, - isVideoPodHostValid, isVideoTagsValid, isVideoThumbnailValid, isVideoThumbnail64Valid @@ -74,11 +73,6 @@ function isVideoNameValid (value) { return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.NAME) } -function isVideoPodHostValid (value) { - // TODO: set options (TLD...) - return validator.isURL(value) -} - function isVideoTagsValid (tags) { return miscValidators.isArray(tags) && validator.isInt(tags.length, VIDEOS_CONSTRAINTS_FIELDS.TAGS) && -- cgit v1.2.3 From 4d32448895ad29ef694bcf790d59253249ad5939 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 29 Dec 2016 12:13:19 +0100 Subject: Server: use binary data instead of base64 to send thumbnails --- server/helpers/custom-validators/videos.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'server/helpers/custom-validators') diff --git a/server/helpers/custom-validators/videos.js b/server/helpers/custom-validators/videos.js index da857ba5f..4aaa6aaa9 100644 --- a/server/helpers/custom-validators/videos.js +++ b/server/helpers/custom-validators/videos.js @@ -17,7 +17,7 @@ const videosValidators = { isVideoNameValid, isVideoTagsValid, isVideoThumbnailValid, - isVideoThumbnail64Valid + isVideoThumbnailDataValid } function isEachRemoteVideosValid (requests) { @@ -33,7 +33,7 @@ function isEachRemoteVideosValid (requests) { isVideoInfoHashValid(video.infoHash) && isVideoNameValid(video.name) && isVideoTagsValid(video.tags) && - isVideoThumbnail64Valid(video.thumbnailBase64) && + isVideoThumbnailDataValid(video.thumbnailData) && isVideoRemoteIdValid(video.remoteId) && isVideoExtnameValid(video.extname) ) || @@ -86,9 +86,8 @@ function isVideoThumbnailValid (value) { return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.THUMBNAIL) } -function isVideoThumbnail64Valid (value) { - return validator.isBase64(value) && - validator.isByteLength(value, VIDEOS_CONSTRAINTS_FIELDS.THUMBNAIL64) +function isVideoThumbnailDataValid (value) { + return validator.isByteLength(value, VIDEOS_CONSTRAINTS_FIELDS.THUMBNAIL_DATA) } function isVideoRemoteIdValid (value) { -- cgit v1.2.3 From 3d118fb501f576a298f6bb059167e4c7f4dd8dcc Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 30 Dec 2016 11:27:42 +0100 Subject: Server: propagate video update to other pods --- server/helpers/custom-validators/videos.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'server/helpers/custom-validators') diff --git a/server/helpers/custom-validators/videos.js b/server/helpers/custom-validators/videos.js index 4aaa6aaa9..b76eec1b5 100644 --- a/server/helpers/custom-validators/videos.js +++ b/server/helpers/custom-validators/videos.js @@ -37,6 +37,17 @@ function isEachRemoteVideosValid (requests) { isVideoRemoteIdValid(video.remoteId) && isVideoExtnameValid(video.extname) ) || + ( + isRequestTypeUpdateValid(request.type) && + isVideoDateValid(video.createdAt) && + isVideoDescriptionValid(video.description) && + isVideoDurationValid(video.duration) && + isVideoInfoHashValid(video.infoHash) && + isVideoNameValid(video.name) && + isVideoTagsValid(video.tags) && + isVideoRemoteIdValid(video.remoteId) && + isVideoExtnameValid(video.extname) + ) || ( isRequestTypeRemoveValid(request.type) && isVideoNameValid(video.name) && @@ -104,6 +115,10 @@ function isRequestTypeAddValid (value) { return value === 'add' } +function isRequestTypeUpdateValid (value) { + return value === 'update' +} + function isRequestTypeRemoveValid (value) { return value === 'remove' } -- cgit v1.2.3 From 79066fdf33f79d2d41394f10881e2c226ca26b49 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 30 Dec 2016 11:45:00 +0100 Subject: Server: add updatedAt attribute to videos --- server/helpers/custom-validators/videos.js | 2 ++ 1 file changed, 2 insertions(+) (limited to 'server/helpers/custom-validators') diff --git a/server/helpers/custom-validators/videos.js b/server/helpers/custom-validators/videos.js index b76eec1b5..8448386d9 100644 --- a/server/helpers/custom-validators/videos.js +++ b/server/helpers/custom-validators/videos.js @@ -28,6 +28,7 @@ function isEachRemoteVideosValid (requests) { isRequestTypeAddValid(request.type) && isVideoAuthorValid(video.author) && isVideoDateValid(video.createdAt) && + isVideoDateValid(video.updatedAt) && isVideoDescriptionValid(video.description) && isVideoDurationValid(video.duration) && isVideoInfoHashValid(video.infoHash) && @@ -40,6 +41,7 @@ function isEachRemoteVideosValid (requests) { ( isRequestTypeUpdateValid(request.type) && isVideoDateValid(video.createdAt) && + isVideoDateValid(video.updatedAt) && isVideoDescriptionValid(video.description) && isVideoDurationValid(video.duration) && isVideoInfoHashValid(video.infoHash) && -- cgit v1.2.3 From 55fa55a9be566cca2ba95322f2ae23b434aed62a Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 4 Jan 2017 20:59:23 +0100 Subject: Server: add video abuse support --- server/helpers/custom-validators/index.js | 2 + server/helpers/custom-validators/remote/index.js | 11 ++++ server/helpers/custom-validators/remote/videos.js | 74 +++++++++++++++++++++++ server/helpers/custom-validators/videos.js | 66 ++++---------------- 4 files changed, 100 insertions(+), 53 deletions(-) create mode 100644 server/helpers/custom-validators/remote/index.js create mode 100644 server/helpers/custom-validators/remote/videos.js (limited to 'server/helpers/custom-validators') 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 @@ const miscValidators = require('./misc') const podsValidators = require('./pods') +const remoteValidators = require('./remote') const usersValidators = require('./users') const videosValidators = require('./videos') const validators = { misc: miscValidators, pods: podsValidators, + remote: remoteValidators, users: usersValidators, videos: videosValidators } 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 @@ +'use strict' + +const remoteVideosValidators = require('./videos') + +const validators = { + videos: remoteVideosValidators +} + +// --------------------------------------------------------------------------- + +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 @@ +'use strict' + +const videosValidators = require('../videos') +const miscValidators = require('../misc') + +const remoteVideosValidators = { + isEachRemoteRequestVideosValid +} + +function isEachRemoteRequestVideosValid (requests) { + return miscValidators.isArray(requests) && + requests.every(function (request) { + const video = request.data + return ( + isRequestTypeAddValid(request.type) && + videosValidators.isVideoAuthorValid(video.author) && + videosValidators.isVideoDateValid(video.createdAt) && + videosValidators.isVideoDateValid(video.updatedAt) && + videosValidators.isVideoDescriptionValid(video.description) && + videosValidators.isVideoDurationValid(video.duration) && + videosValidators.isVideoInfoHashValid(video.infoHash) && + videosValidators.isVideoNameValid(video.name) && + videosValidators.isVideoTagsValid(video.tags) && + videosValidators.isVideoThumbnailDataValid(video.thumbnailData) && + videosValidators.isVideoRemoteIdValid(video.remoteId) && + videosValidators.isVideoExtnameValid(video.extname) + ) || + ( + isRequestTypeUpdateValid(request.type) && + videosValidators.isVideoDateValid(video.createdAt) && + videosValidators.isVideoDateValid(video.updatedAt) && + videosValidators.isVideoDescriptionValid(video.description) && + videosValidators.isVideoDurationValid(video.duration) && + videosValidators.isVideoInfoHashValid(video.infoHash) && + videosValidators.isVideoNameValid(video.name) && + videosValidators.isVideoTagsValid(video.tags) && + videosValidators.isVideoRemoteIdValid(video.remoteId) && + videosValidators.isVideoExtnameValid(video.extname) + ) || + ( + isRequestTypeRemoveValid(request.type) && + videosValidators.isVideoNameValid(video.name) && + videosValidators.isVideoRemoteIdValid(video.remoteId) + ) || + ( + isRequestTypeReportAbuseValid(request.type) && + videosValidators.isVideoRemoteIdValid(request.data.videoRemoteId) && + videosValidators.isVideoAbuseReasonValid(request.data.reportReason) && + videosValidators.isVideoAbuseReporterUsernameValid(request.data.reporterUsername) + ) + }) +} + +// --------------------------------------------------------------------------- + +module.exports = remoteVideosValidators + +// --------------------------------------------------------------------------- + +function isRequestTypeAddValid (value) { + return value === 'add' +} + +function isRequestTypeUpdateValid (value) { + return value === 'update' +} + +function isRequestTypeRemoveValid (value) { + return value === 'remove' +} + +function isRequestTypeReportAbuseValid (value) { + return value === 'report-abuse' +} 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') const usersValidators = require('./users') const miscValidators = require('./misc') const VIDEOS_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.VIDEOS +const VIDEO_ABUSES_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.VIDEO_ABUSES const videosValidators = { - isEachRemoteVideosValid, isVideoAuthorValid, isVideoDateValid, isVideoDescriptionValid, @@ -17,45 +17,11 @@ const videosValidators = { isVideoNameValid, isVideoTagsValid, isVideoThumbnailValid, - isVideoThumbnailDataValid -} - -function isEachRemoteVideosValid (requests) { - return miscValidators.isArray(requests) && - requests.every(function (request) { - const video = request.data - return ( - isRequestTypeAddValid(request.type) && - isVideoAuthorValid(video.author) && - isVideoDateValid(video.createdAt) && - isVideoDateValid(video.updatedAt) && - isVideoDescriptionValid(video.description) && - isVideoDurationValid(video.duration) && - isVideoInfoHashValid(video.infoHash) && - isVideoNameValid(video.name) && - isVideoTagsValid(video.tags) && - isVideoThumbnailDataValid(video.thumbnailData) && - isVideoRemoteIdValid(video.remoteId) && - isVideoExtnameValid(video.extname) - ) || - ( - isRequestTypeUpdateValid(request.type) && - isVideoDateValid(video.createdAt) && - isVideoDateValid(video.updatedAt) && - isVideoDescriptionValid(video.description) && - isVideoDurationValid(video.duration) && - isVideoInfoHashValid(video.infoHash) && - isVideoNameValid(video.name) && - isVideoTagsValid(video.tags) && - isVideoRemoteIdValid(video.remoteId) && - isVideoExtnameValid(video.extname) - ) || - ( - isRequestTypeRemoveValid(request.type) && - isVideoNameValid(video.name) && - isVideoRemoteIdValid(video.remoteId) - ) - }) + isVideoThumbnailDataValid, + isVideoExtnameValid, + isVideoRemoteIdValid, + isVideoAbuseReasonValid, + isVideoAbuseReporterUsernameValid } function isVideoAuthorValid (value) { @@ -107,20 +73,14 @@ function isVideoRemoteIdValid (value) { return validator.isUUID(value, 4) } -// --------------------------------------------------------------------------- - -module.exports = videosValidators - -// --------------------------------------------------------------------------- - -function isRequestTypeAddValid (value) { - return value === 'add' +function isVideoAbuseReasonValid (value) { + return validator.isLength(value, VIDEO_ABUSES_CONSTRAINTS_FIELDS.REASON) } -function isRequestTypeUpdateValid (value) { - return value === 'update' +function isVideoAbuseReporterUsernameValid (value) { + return usersValidators.isUserUsernameValid(value) } -function isRequestTypeRemoveValid (value) { - return value === 'remove' -} +// --------------------------------------------------------------------------- + +module.exports = videosValidators -- cgit v1.2.3 From b981a525c37d226b3fa59287a6ce338f54583d0c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 4 Jan 2017 21:15:57 +0100 Subject: Server: we don't need the video name when removing a remote video --- server/helpers/custom-validators/remote/videos.js | 1 - 1 file changed, 1 deletion(-) (limited to 'server/helpers/custom-validators') diff --git a/server/helpers/custom-validators/remote/videos.js b/server/helpers/custom-validators/remote/videos.js index c3ca00e1c..7c27b9dbb 100644 --- a/server/helpers/custom-validators/remote/videos.js +++ b/server/helpers/custom-validators/remote/videos.js @@ -39,7 +39,6 @@ function isEachRemoteRequestVideosValid (requests) { ) || ( isRequestTypeRemoveValid(request.type) && - videosValidators.isVideoNameValid(video.name) && videosValidators.isVideoRemoteIdValid(video.remoteId) ) || ( -- cgit v1.2.3