mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 09:07:47 +01:00
Merge pull request #152 from Joe-Dowd/nosegments-404-to-array
get segments by hash 404 to array
This commit is contained in:
commit
03a142ff62
2 changed files with 4 additions and 7 deletions
|
@ -20,10 +20,6 @@ module.exports = async function (req, res) {
|
|||
|
||||
// Get all video id's that match hash prefix
|
||||
const videoIds = db.prepare('all', 'SELECT DISTINCT videoId, hashedVideoID from sponsorTimes WHERE hashedVideoID LIKE ?', [hashPrefix+'%']);
|
||||
if (videoIds.length === 0) {
|
||||
res.sendStatus(404);
|
||||
return;
|
||||
}
|
||||
|
||||
let segments = videoIds.map((video) => {
|
||||
return {
|
||||
|
@ -33,5 +29,5 @@ module.exports = async function (req, res) {
|
|||
};
|
||||
});
|
||||
|
||||
res.status(200).json(segments);
|
||||
res.status((segments.length === 0) ? 404 : 200).json(segments);
|
||||
}
|
|
@ -40,14 +40,15 @@ describe('getSegmentsByHash', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it('Should be able to get a 404 if no videos', (done) => {
|
||||
it('Should be able to get an empty array if no videos', (done) => {
|
||||
request.get(utils.getbaseURL()
|
||||
+ '/api/skipSegments/11111?categories=["shilling"]', null,
|
||||
(err, res, body) => {
|
||||
if (err) done("Couldn't call endpoint");
|
||||
else if (res.statusCode !== 404) done("non 404 status code, was " + res.statusCode);
|
||||
else {
|
||||
done(); // pass
|
||||
if (JSON.parse(body).length === 0 && body === '[]') done(); // pass
|
||||
else done("non empty array returned");
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue