Only sponsors must be longer than 1 second.

Also added proper error message when submission is too short.
This commit is contained in:
Ajay Ramachandran 2020-05-16 18:33:16 -04:00
parent 88a9628e7e
commit a2caa53664
2 changed files with 27 additions and 1 deletions

View file

@ -147,13 +147,19 @@ module.exports = async function postSkipSegments(req, res) {
let startTime = parseFloat(segments[i].segment[0]);
let endTime = parseFloat(segments[i].segment[1]);
if (Math.abs(startTime - endTime) < 1 || isNaN(startTime) || isNaN(endTime)
if (isNaN(startTime) || isNaN(endTime)
|| startTime === Infinity || endTime === Infinity || startTime > endTime) {
//invalid request
res.sendStatus(400);
return;
}
if (segments[i].category === "sponsor" && Math.abs(startTime - endTime) < 1) {
// Too short
res.status(400).send("Sponsors must be longer than 1 second long");
return;
}
//check if this info has already been submitted before
let duplicateCheck2Row = db.prepare("SELECT COUNT(*) as count FROM sponsorTimes WHERE startTime = ? " +
"and endTime = ? and category = ? and videoID = ?").get(startTime, endTime, segments[i].category, videoID);

View file

@ -90,6 +90,26 @@ describe('postSkipSegments', () => {
});
});
it('Should be accepted if a non-sponsor is less than 1 second', (done) => {
request.post(utils.getbaseURL()
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testing&category=intro", null,
(err, res, body) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode === 200) done(); // pass
else done("non 200 status code: " + res.statusCode + " ("+body+")");
});
});
it('Should be rejected if a sponsor is less than 1 second', (done) => {
request.post(utils.getbaseURL()
+ "/api/skipSegments?videoID=qqwerty&startTime=30&endTime=30.5&userID=testing", null,
(err, res, body) => {
if (err) done("Couldn't call endpoint");
else if (res.statusCode === 400) done(); // pass
else done("non 403 status code: " + res.statusCode + " ("+body+")");
});
});
it('Should be rejected if over 80% of the video', (done) => {
request.get(utils.getbaseURL()
+ "/api/postVideoSponsorTimes?videoID=qqwerty&startTime=30&endTime=1000000&userID=testing", null,