mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-07 03:57:06 +03:00
clearCache after shadowban
This commit is contained in:
@@ -2,6 +2,9 @@ import {db, privateDB} from '../databases/databases';
|
|||||||
import {getHash} from '../utils/getHash';
|
import {getHash} from '../utils/getHash';
|
||||||
import {Request, Response} from 'express';
|
import {Request, Response} from 'express';
|
||||||
import { config } from '../config';
|
import { config } from '../config';
|
||||||
|
import { Category, Service, VideoID, VideoIDHash } from '../types/segments.model';
|
||||||
|
import { UserID } from '../types/user.model';
|
||||||
|
import { QueryCacher } from '../utils/queryCacher';
|
||||||
|
|
||||||
export async function shadowBanUser(req: Request, res: Response) {
|
export async function shadowBanUser(req: Request, res: Response) {
|
||||||
const userID = req.query.userID as string;
|
const userID = req.query.userID as string;
|
||||||
@@ -49,6 +52,11 @@ export async function shadowBanUser(req: Request, res: Response) {
|
|||||||
await db.prepare('run', `UPDATE "sponsorTimes" SET "shadowHidden" = 1 WHERE "userID" = ? AND "category" in (${categories.map((c) => `'${c}'`).join(",")})
|
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
|
AND NOT EXISTS ( SELECT "videoID", "category" FROM "lockCategories" WHERE
|
||||||
"sponsorTimes"."videoID" = "lockCategories"."videoID" AND "sponsorTimes"."category" = "lockCategories"."category")`, [userID]);
|
"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]))
|
||||||
|
.map((videoInfo: {category: Category, videoID: VideoID, hashedVideoID: VideoIDHash, service: Service, userID: UserID}) => {
|
||||||
|
QueryCacher.clearVideoCache(videoInfo);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else if (!enabled && row.userCount > 0) {
|
} else if (!enabled && row.userCount > 0) {
|
||||||
//remove them from the shadow ban list
|
//remove them from the shadow ban list
|
||||||
@@ -64,7 +72,13 @@ export async function shadowBanUser(req: Request, res: Response) {
|
|||||||
|
|
||||||
await Promise.all(allSegments.filter((item: {uuid: string}) => {
|
await Promise.all(allSegments.filter((item: {uuid: string}) => {
|
||||||
return segmentsToIgnore.indexOf(item) === -1;
|
return segmentsToIgnore.indexOf(item) === -1;
|
||||||
}).map((UUID: string) => {
|
}).map(async (UUID: string) => {
|
||||||
|
// collect list for unshadowbanning
|
||||||
|
(await db.prepare('all', `SELECT "videoID", "hashedVideoID", "service", "votes", "views", "userID" FROM "sponsorTimes" WHERE "UUID" = ? AND "shadowHidden" = 1 AND "category" in (${categories.map((c) => `'${c}'`).join(",")})`, [UUID]))
|
||||||
|
.map((videoInfo: {category: Category, videoID: VideoID, hashedVideoID: VideoIDHash, service: Service, userID: UserID}) => {
|
||||||
|
QueryCacher.clearVideoCache(videoInfo);
|
||||||
|
})
|
||||||
|
// unhide
|
||||||
return db.prepare('run', `UPDATE "sponsorTimes" SET "shadowHidden" = 0 WHERE "UUID" = ? AND "category" in (${categories.map((c) => `'${c}'`).join(",")})`, [UUID]);
|
return db.prepare('run', `UPDATE "sponsorTimes" SET "shadowHidden" = 0 WHERE "UUID" = ? AND "category" in (${categories.map((c) => `'${c}'`).join(",")})`, [UUID]);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user