mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-16 08:26:59 +03:00
fix eslint-errors
This commit is contained in:
@@ -2,7 +2,7 @@ import {db} from '../databases/databases';
|
||||
import {Request, Response} from 'express';
|
||||
import {UserID} from '../types/user.model';
|
||||
|
||||
function getFuzzyUserID(userName: String): Promise<{userName: String, userID: UserID }[]> {
|
||||
function getFuzzyUserID(userName: string): Promise<{userName: string, userID: UserID }[]> {
|
||||
// escape [_ % \] to avoid ReDOS
|
||||
userName = userName.replace(/\\/g, '\\\\')
|
||||
.replace(/_/g, '\\_')
|
||||
@@ -11,13 +11,13 @@ function getFuzzyUserID(userName: String): Promise<{userName: String, userID: Us
|
||||
// LIMIT to reduce overhead | ESCAPE to escape LIKE wildcards
|
||||
try {
|
||||
return db.prepare('all', `SELECT "userName", "userID" FROM "userNames" WHERE "userName"
|
||||
LIKE ? ESCAPE '\\' LIMIT 10`, [userName])
|
||||
LIKE ? ESCAPE '\\' LIMIT 10`, [userName]);
|
||||
} catch (err) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function getExactUserID(userName: String): Promise<{userName: String, userID: UserID }[]> {
|
||||
function getExactUserID(userName: string): Promise<{userName: string, userID: UserID }[]> {
|
||||
try {
|
||||
return db.prepare('all', `SELECT "userName", "userID" from "userNames" WHERE "userName" = ? LIMIT 10`, [userName]);
|
||||
} catch (err) {
|
||||
@@ -25,31 +25,27 @@ function getExactUserID(userName: String): Promise<{userName: String, userID: Us
|
||||
}
|
||||
}
|
||||
|
||||
export async function getUserID(req: Request, res: Response) {
|
||||
let userName = req.query.username as string;
|
||||
export async function getUserID(req: Request, res: Response): Promise<Response> {
|
||||
const userName = req.query.username as string;
|
||||
const exactSearch = req.query.exact
|
||||
? req.query.exact == "true"
|
||||
: false as Boolean;
|
||||
: false as boolean;
|
||||
|
||||
// if not exact and length is 1, also skip
|
||||
if (userName == undefined || userName.length > 64 ||
|
||||
(!exactSearch && userName.length < 3)) {
|
||||
// invalid request
|
||||
res.sendStatus(400);
|
||||
return false;
|
||||
return res.sendStatus(400);
|
||||
}
|
||||
const results = exactSearch
|
||||
? await getExactUserID(userName)
|
||||
: await getFuzzyUserID(userName);
|
||||
|
||||
if (results === undefined || results === null) {
|
||||
res.sendStatus(500);
|
||||
return false;
|
||||
return res.sendStatus(500);
|
||||
} else if (results.length === 0) {
|
||||
res.sendStatus(404);
|
||||
return false;
|
||||
return res.sendStatus(404);
|
||||
} else {
|
||||
res.send(results);
|
||||
return false;
|
||||
return res.send(results);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user