Merge pull request #343 from mchangrh/409-ban-exists

re-shadowban user
This commit is contained in:
Ajay Ramachandran
2021-08-28 00:20:22 -04:00
committed by GitHub
2 changed files with 62 additions and 10 deletions

View File

@@ -48,16 +48,7 @@ export async function shadowBanUser(req: Request, res: Response): Promise<Respon
//find all previous submissions and hide them
if (unHideOldSubmissions) {
await db.prepare("run", `UPDATE "sponsorTimes" SET "shadowHidden" = 1 WHERE "userID" = ? AND "category" in (${categories.map((c) => `'${c}'`).join(",")})
AND NOT EXISTS ( SELECT "videoID", "category" FROM "lockCategories" WHERE
"sponsorTimes"."videoID" = "lockCategories"."videoID" AND "sponsorTimes"."category" = "lockCategories"."category")`, [userID]);
// clear cache for all old videos
(await db.prepare("all", `SELECT "videoID", "hashedVideoID", "service", "votes", "views" FROM "sponsorTimes" WHERE "userID" = ?`, [userID]))
.forEach((videoInfo: {category: Category, videoID: VideoID, hashedVideoID: VideoIDHash, service: Service, userID: UserID}) => {
QueryCacher.clearVideoCache(videoInfo);
}
);
await unHideSubmissions(categories, userID);
}
} else if (!enabled && row.userCount > 0) {
//remove them from the shadow ban list
@@ -84,6 +75,16 @@ export async function shadowBanUser(req: Request, res: Response): Promise<Respon
return db.prepare("run", `UPDATE "sponsorTimes" SET "shadowHidden" = 0 WHERE "UUID" = ? AND "category" in (${categories.map((c) => `'${c}'`).join(",")})`, [UUID]);
}));
}
// already shadowbanned
} else if (enabled && row.userCount > 0) {
// apply unHideOldSubmissions if applicable
if (unHideOldSubmissions) {
await unHideSubmissions(categories, userID);
return res.sendStatus(200);
}
// otherwise ban already exists, send 409
return res.sendStatus(409);
}
} else if (hashedIP) {
//check to see if this user is already shadowbanned
@@ -115,3 +116,16 @@ export async function shadowBanUser(req: Request, res: Response): Promise<Respon
}
return res.sendStatus(200);
}
async function unHideSubmissions(categories: string[], userID: UserID) {
await db.prepare("run", `UPDATE "sponsorTimes" SET "shadowHidden" = 1 WHERE "userID" = ? AND "category" in (${categories.map((c) => `'${c}'`).join(",")})
AND NOT EXISTS ( SELECT "videoID", "category" FROM "lockCategories" WHERE
"sponsorTimes"."videoID" = "lockCategories"."videoID" AND "sponsorTimes"."category" = "lockCategories"."category")`, [userID]);
// clear cache for all old videos
(await db.prepare("all", `SELECT "videoID", "hashedVideoID", "service", "votes", "views" FROM "sponsorTimes" WHERE "userID" = ?`, [userID]))
.forEach((videoInfo: { category: Category; videoID: VideoID; hashedVideoID: VideoIDHash; service: Service; userID: UserID; }) => {
QueryCacher.clearVideoCache(videoInfo);
}
); //eslint-disable-line
}