X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fhelpers%2Fcustom-validators%2Fvideos.js;h=c5a1f3cb5684d24af5932671497c2e528b9d10ae;hb=e4c87ec26962e359d1c70b03ed188a3f19d6a25b;hp=7f727854dfc8e99c2eea8cea0ffa23d0c52cf3cb;hpb=99fe265a5fc077cb66c322e7f3d191ff7110aea0;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/helpers/custom-validators/videos.js b/server/helpers/custom-validators/videos.js index 7f727854d..c5a1f3cb5 100644 --- a/server/helpers/custom-validators/videos.js +++ b/server/helpers/custom-validators/videos.js @@ -7,6 +7,7 @@ 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 VIDEO_EVENTS_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.VIDEO_EVENTS const videosValidators = { isVideoAuthorValid, @@ -21,7 +22,12 @@ const videosValidators = { isVideoExtnameValid, isVideoRemoteIdValid, isVideoAbuseReasonValid, - isVideoAbuseReporterUsernameValid + isVideoAbuseReporterUsernameValid, + isVideoFile, + isVideoViewsValid, + isVideoLikesValid, + isVideoDislikesValid, + isVideoEventCountValid } function isVideoAuthorValid (value) { @@ -81,6 +87,37 @@ function isVideoAbuseReporterUsernameValid (value) { return usersValidators.isUserUsernameValid(value) } +function isVideoViewsValid (value) { + return validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.VIEWS) +} + +function isVideoLikesValid (value) { + return validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.LIKES) +} + +function isVideoDislikesValid (value) { + return validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.DISLIKES) +} + +function isVideoEventCountValid (value) { + return validator.isInt(value + '', VIDEO_EVENTS_CONSTRAINTS_FIELDS.COUNT) +} + +function isVideoFile (value, files) { + // Should have files + if (!files) return false + + // Should have videofile file + const videofile = files.videofile + if (!videofile || videofile.length === 0) return false + + // The file should exist + const file = videofile[0] + if (!file || !file.originalname) return false + + return new RegExp('^video/(webm|mp4|ogg)$', 'i').test(file.mimetype) +} + // --------------------------------------------------------------------------- module.exports = videosValidators