Skip to content
Snippets Groups Projects
Commit f6f7dfee authored by Chocobozzz's avatar Chocobozzz
Browse files

Server: update express-validator

parent c70e0710
No related branches found
No related tags found
No related merge requests found
......@@ -21,7 +21,8 @@ const videosValidators = {
isVideoExtnameValid,
isVideoRemoteIdValid,
isVideoAbuseReasonValid,
isVideoAbuseReporterUsernameValid
isVideoAbuseReporterUsernameValid,
isVideoFile
}
function isVideoAuthorValid (value) {
......@@ -81,6 +82,21 @@ function isVideoAbuseReporterUsernameValid (value) {
return usersValidators.isUserUsernameValid(value)
}
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
......@@ -17,9 +17,7 @@ const validatorsVideos = {
}
function videosAdd (req, res, next) {
req.checkFiles('videofile[0].originalname', 'Should have an input video').notEmpty()
// TODO: move to constants and function
req.checkFiles('videofile[0].mimetype', 'Should have a correct mime type').matches(/video\/(webm)|(mp4)|(ogg)/i)
req.checkBody('videofile', 'Should have a valid file').isVideoFile(req.files)
req.checkBody('name', 'Should have a valid name').isVideoNameValid()
req.checkBody('description', 'Should have a valid description').isVideoDescriptionValid()
req.checkBody('tags', 'Should have correct tags').isVideoTagsValid()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment