mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-27 01:48:33 +03:00
fix eslint-errors
This commit is contained in:
@@ -2,7 +2,7 @@ import { Request, Response } from 'express';
|
||||
import { db } from '../databases/databases';
|
||||
import { DBSegment, SegmentUUID } from "../types/segments.model";
|
||||
|
||||
const isValidSegmentUUID = (str: string): Boolean => /^([a-f0-9]{64}|[a-f0-9]{8}\-[a-f0-9]{4}\-[a-f0-9]{4}\-[a-f0-9]{4}\-[a-f0-9]{12})/.test(str)
|
||||
const isValidSegmentUUID = (str: string): boolean => /^([a-f0-9]{64}|[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})/.test(str);
|
||||
|
||||
async function getSegmentFromDBByUUID(UUID: SegmentUUID): Promise<DBSegment> {
|
||||
try {
|
||||
@@ -18,7 +18,7 @@ async function getSegmentFromDBByUUID(UUID: SegmentUUID): Promise<DBSegment> {
|
||||
|
||||
async function getSegmentsByUUID(UUIDs: SegmentUUID[]): Promise<DBSegment[]> {
|
||||
const DBSegments: DBSegment[] = [];
|
||||
for (let UUID of UUIDs) {
|
||||
for (const UUID of UUIDs) {
|
||||
// if UUID is invalid, skip
|
||||
if (!isValidSegmentUUID(UUID)) continue;
|
||||
DBSegments.push(await getSegmentFromDBByUUID(UUID as SegmentUUID));
|
||||
@@ -26,7 +26,7 @@ async function getSegmentsByUUID(UUIDs: SegmentUUID[]): Promise<DBSegment[]> {
|
||||
return DBSegments;
|
||||
}
|
||||
|
||||
async function handleGetSegmentInfo(req: Request, res: Response) {
|
||||
async function handleGetSegmentInfo(req: Request, res: Response): Promise<DBSegment[]> {
|
||||
// If using params instead of JSON, only one UUID can be pulled
|
||||
let UUIDs = req.query.UUIDs
|
||||
? JSON.parse(req.query.UUIDs as string)
|
||||
@@ -41,18 +41,18 @@ async function handleGetSegmentInfo(req: Request, res: Response) {
|
||||
if (UUIDs.length > 10) UUIDs = UUIDs.slice(0, 10);
|
||||
if (!Array.isArray(UUIDs) || !UUIDs) {
|
||||
res.status(400).send("UUIDs parameter does not match format requirements.");
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
const DBSegments = await getSegmentsByUUID(UUIDs);
|
||||
// all uuids failed lookup
|
||||
if (!DBSegments?.length) {
|
||||
res.sendStatus(400);
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
// uuids valid but not found
|
||||
if (DBSegments[0] === null || DBSegments[0] === undefined) {
|
||||
res.sendStatus(400);
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
return DBSegments;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user