mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 01:02:30 +01:00
parse repeated parameters
This commit is contained in:
parent
1770608525
commit
dd74dd3b1b
4 changed files with 56 additions and 5 deletions
|
@ -29,10 +29,12 @@ async function getSegmentsByUUID(UUIDs: SegmentUUID[]): Promise<DBSegment[]> {
|
||||||
async function handleGetSegmentInfo(req: Request, res: Response) {
|
async function handleGetSegmentInfo(req: Request, res: Response) {
|
||||||
// If using params instead of JSON, only one UUID can be pulled
|
// If using params instead of JSON, only one UUID can be pulled
|
||||||
let UUIDs = req.query.UUIDs
|
let UUIDs = req.query.UUIDs
|
||||||
? JSON.parse(req.query.UUIDs as string)
|
? JSON.parse(req.query.UUIDs as string)
|
||||||
: req.query.UUID
|
: req.query.UUID
|
||||||
? [req.query.UUID]
|
? Array.isArray(req.query.UUID)
|
||||||
: null;
|
? req.query.UUID
|
||||||
|
: [req.query.UUID]
|
||||||
|
: null;
|
||||||
// deduplicate with set
|
// deduplicate with set
|
||||||
UUIDs = [ ...new Set(UUIDs)];
|
UUIDs = [ ...new Set(UUIDs)];
|
||||||
// if more than 10 entries, slice
|
// if more than 10 entries, slice
|
||||||
|
|
|
@ -268,7 +268,9 @@ async function handleGetSegments(req: Request, res: Response): Promise<Segment[]
|
||||||
const categories = req.query.categories
|
const categories = req.query.categories
|
||||||
? JSON.parse(req.query.categories as string)
|
? JSON.parse(req.query.categories as string)
|
||||||
: req.query.category
|
: req.query.category
|
||||||
? [req.query.category]
|
? Array.isArray(req.query.category)
|
||||||
|
? req.query.category
|
||||||
|
: [req.query.category]
|
||||||
: ['sponsor'];
|
: ['sponsor'];
|
||||||
if (!Array.isArray(categories)) {
|
if (!Array.isArray(categories)) {
|
||||||
res.status(400).send("Categories parameter does not match format requirements.");
|
res.status(400).send("Categories parameter does not match format requirements.");
|
||||||
|
|
|
@ -309,4 +309,22 @@ describe('getSegmentInfo', () => {
|
||||||
})
|
})
|
||||||
.catch(err => ("couldn't call endpoint"));
|
.catch(err => ("couldn't call endpoint"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Should be able to retreive multiple segments with multiple parameters', (done: Done) => {
|
||||||
|
fetch(getbaseURL() + `/api/segmentInfo?UUID=${upvotedID}&UUID=${downvotedID}`)
|
||||||
|
.then(async res => {
|
||||||
|
if (res.status !== 200) done("Status code was: " + res.status);
|
||||||
|
else {
|
||||||
|
const data = await res.json();
|
||||||
|
if (data.length === 2 &&
|
||||||
|
(data[0].videoID === "upvoted" && data[0].votes === 2) &&
|
||||||
|
(data[1].videoID === "downvoted" && data[1].votes === -2)) {
|
||||||
|
done();
|
||||||
|
} else {
|
||||||
|
done("Received incorrect body: " + (await res.text()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => "Couldn't call endpoint");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -264,4 +264,33 @@ describe('getSkipSegments', () => {
|
||||||
.catch(err => ("Couldn't call endpoint"));
|
.catch(err => ("Couldn't call endpoint"));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Should be able to get multiple categories with repeating parameters', (done: Done) => {
|
||||||
|
fetch(getbaseURL() + "/api/skipSegments?videoID=testtesttest&category=sponsor&category=intro")
|
||||||
|
.then(async res => {
|
||||||
|
if (res.status !== 200) done("Status code was: " + res.status);
|
||||||
|
else {
|
||||||
|
const body = await res.text();
|
||||||
|
const data = JSON.parse(body);
|
||||||
|
if (data.length === 2) {
|
||||||
|
|
||||||
|
let success = true;
|
||||||
|
for (const segment of data) {
|
||||||
|
if ((segment.segment[0] !== 20 || segment.segment[1] !== 33
|
||||||
|
|| segment.category !== "intro" || segment.UUID !== "1-uuid-2") &&
|
||||||
|
(segment.segment[0] !== 1 || segment.segment[1] !== 11
|
||||||
|
|| segment.category !== "sponsor" || segment.UUID !== "1-uuid-0")) {
|
||||||
|
success = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (success) done();
|
||||||
|
else done("Received incorrect body: " + body);
|
||||||
|
} else {
|
||||||
|
done("Received incorrect body: " + body);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => ("Couldn't call endpoint"));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue