Merge pull request #178 from FoseFx/fosefx-errorh

Improve missing fields checks (POST skipSegment)
This commit is contained in:
Ajay Ramachandran 2020-10-21 10:57:43 -04:00 committed by GitHub
commit c462323dd5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -257,11 +257,22 @@ module.exports = async function postSkipSegments(req, res) {
}];
}
//check if all correct inputs are here and the length is 1 second or more
if (videoID == undefined || userID == undefined || segments == undefined || segments.length < 1) {
//invalid request
res.status(400).send("Parameters are not valid");
return;
const invalidFields = [];
if (typeof videoID !== 'string') {
invalidFields.push('videoID');
}
if (typeof userID !== 'string') {
invalidFields.push('userID');
}
if (!Array.isArray(segments) || segments.length < 1) {
invalidFields.push('segments');
}
if (invalidFields.length !== 0) {
// invalid request
const fields = invalidFields.reduce((p, c, i) => p + (i !== 0 ? ', ' : '') + c, '');
res.status(400).send(`No valid ${fields} field(s) provided`);
return;
}
//hash the userID