mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-30 03:18:23 +03:00
Handle exceptions, and prevent crashing from unhandled exceptions
This commit is contained in:
@@ -34,29 +34,29 @@ export async function setUsername(req: Request, res: Response): Promise<Response
|
||||
// eslint-disable-next-line no-control-regex
|
||||
userName = userName.replace(/[\u0000-\u001F\u007F-\u009F]/g, "");
|
||||
|
||||
// check privateID against publicID
|
||||
if (!await checkPrivateUsername(userName, userID)) {
|
||||
return res.sendStatus(400);
|
||||
}
|
||||
|
||||
timings.push(Date.now());
|
||||
|
||||
if (adminUserIDInput != undefined) {
|
||||
//this is the admin controlling the other users account, don't hash the controling account's ID
|
||||
adminUserIDInput = await getHashCache(adminUserIDInput);
|
||||
|
||||
if (adminUserIDInput != config.adminUserID) {
|
||||
//they aren't the admin
|
||||
return res.sendStatus(403);
|
||||
}
|
||||
} else {
|
||||
//hash the userID
|
||||
userID = await getHashCache(userID);
|
||||
}
|
||||
|
||||
timings.push(Date.now());
|
||||
|
||||
try {
|
||||
// check privateID against publicID
|
||||
if (!await checkPrivateUsername(userName, userID)) {
|
||||
return res.sendStatus(400);
|
||||
}
|
||||
|
||||
timings.push(Date.now());
|
||||
|
||||
if (adminUserIDInput != undefined) {
|
||||
//this is the admin controlling the other users account, don't hash the controling account's ID
|
||||
adminUserIDInput = await getHashCache(adminUserIDInput);
|
||||
|
||||
if (adminUserIDInput != config.adminUserID) {
|
||||
//they aren't the admin
|
||||
return res.sendStatus(403);
|
||||
}
|
||||
} else {
|
||||
//hash the userID
|
||||
userID = await getHashCache(userID);
|
||||
}
|
||||
|
||||
timings.push(Date.now());
|
||||
|
||||
const row = await db.prepare("get", `SELECT count(*) as "userCount" FROM "userNames" WHERE "userID" = ? AND "locked" = 1`, [userID]);
|
||||
if (adminUserIDInput === undefined && row.userCount > 0) {
|
||||
return res.sendStatus(200);
|
||||
|
||||
Reference in New Issue
Block a user