mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-23 16:08:25 +03:00
minor optimizations
This commit is contained in:
@@ -128,12 +128,7 @@ async function handleGetSegments(req: Request, res: Response): Promise<searchSeg
|
||||
|
||||
const segments = await getSegmentsFromDBByVideoID(videoID, service);
|
||||
|
||||
if (segments === null || segments === undefined) {
|
||||
res.sendStatus(500);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (segments.length === 0) {
|
||||
if (!segments?.length) {
|
||||
res.sendStatus(404);
|
||||
return false;
|
||||
}
|
||||
@@ -155,6 +150,7 @@ function filterSegments(segments: DBSegment[], filters: Record<string, any>, pag
|
||||
);
|
||||
|
||||
if (sortBy !== SortableFields.timeSubmitted) {
|
||||
/* istanbul ignore next */
|
||||
filteredSegments.sort((a,b) => {
|
||||
const key = sortDir === "desc" ? 1 : -1;
|
||||
if (a[sortBy] < b[sortBy]) {
|
||||
@@ -187,6 +183,7 @@ async function endpoint(req: Request, res: Response): Promise<Response> {
|
||||
return res.send(segmentResponse);
|
||||
}
|
||||
} catch (err) {
|
||||
/* istanbul ignore next */
|
||||
if (err instanceof SyntaxError) {
|
||||
return res.status(400).send("Invalid array in parameters");
|
||||
} else return res.sendStatus(500);
|
||||
|
||||
Reference in New Issue
Block a user