mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-11 14:07:09 +03:00
Auto-lock username when admin changes it
https://github.com/ajayyy/SponsorBlockServer/issues/168
This commit is contained in:
@@ -55,14 +55,16 @@ export async function setUsername(req: Request, res: Response) {
|
||||
|
||||
try {
|
||||
//check if username is already set
|
||||
let row = await db.prepare('get', `SELECT count(*) as count FROM "userNames" WHERE "userID" = ?`, [userID]);
|
||||
const row = await db.prepare('get', `SELECT count(*) as count FROM "userNames" WHERE "userID" = ?`, [userID]);
|
||||
const locked = adminUserIDInput === undefined ? 0 : 1;
|
||||
|
||||
if (row.count > 0) {
|
||||
//already exists, update this row
|
||||
await db.prepare('run', `UPDATE "userNames" SET "userName" = ? WHERE "userID" = ?`, [userName, userID]);
|
||||
await db.prepare('run', `UPDATE "userNames" SET "locked" = ? WHERE "userID" = ?`, [locked, userID]);
|
||||
} else {
|
||||
//add to the db
|
||||
await db.prepare('run', `INSERT INTO "userNames"("userID", "userName") VALUES(?, ?)`, [userID, userName]);
|
||||
await db.prepare('run', `INSERT INTO "userNames"("userID", "userName", "locked") VALUES(?, ?, ?)`, [userID, userName, locked]);
|
||||
}
|
||||
|
||||
res.sendStatus(200);
|
||||
|
||||
Reference in New Issue
Block a user