mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-09 13:07:02 +03:00
add service to table only have videoID
This commit is contained in:
@@ -2,14 +2,16 @@ import { Request, Response } from "express";
|
||||
import { isUserVIP } from "../utils/isUserVIP";
|
||||
import { getHash } from "../utils/getHash";
|
||||
import { db } from "../databases/databases";
|
||||
import { Category, VideoID } from "../types/segments.model";
|
||||
import { Category, Service, VideoID } from "../types/segments.model";
|
||||
import { UserID } from "../types/user.model";
|
||||
import { getService } from "../utils/getService";
|
||||
|
||||
export async function deleteLockCategoriesEndpoint(req: Request, res: Response): Promise<Response> {
|
||||
// Collect user input data
|
||||
const videoID = req.body.videoID as VideoID;
|
||||
const userID = req.body.userID as UserID;
|
||||
const categories = req.body.categories as Category[];
|
||||
const service = getService(req.body.service);
|
||||
|
||||
// Check input data is valid
|
||||
if (!videoID
|
||||
@@ -33,7 +35,7 @@ export async function deleteLockCategoriesEndpoint(req: Request, res: Response):
|
||||
});
|
||||
}
|
||||
|
||||
await deleteLockCategories(videoID, categories);
|
||||
await deleteLockCategories(videoID, categories, service);
|
||||
|
||||
return res.status(200).json({ message: `Removed lock categories entrys for video ${videoID}` });
|
||||
}
|
||||
@@ -42,13 +44,20 @@ export async function deleteLockCategoriesEndpoint(req: Request, res: Response):
|
||||
*
|
||||
* @param videoID
|
||||
* @param categories If null, will remove all
|
||||
* @param service
|
||||
*/
|
||||
export async function deleteLockCategories(videoID: VideoID, categories: Category[]): Promise<void> {
|
||||
const entries = (await db.prepare("all", 'SELECT * FROM "lockCategories" WHERE "videoID" = ?', [videoID])).filter((entry: any) => {
|
||||
return categories === null || categories.indexOf(entry.category) !== -1;
|
||||
});
|
||||
export async function deleteLockCategories(videoID: VideoID, categories: Category[], service: Service): Promise<void> {
|
||||
const entries = (
|
||||
await db.prepare("all", 'SELECT * FROM "lockCategories" WHERE "videoID" = ? AND "service" = ?', [videoID, service]))
|
||||
.filter((entry: any) => {
|
||||
return categories === null || categories.indexOf(entry.category) !== -1;
|
||||
});
|
||||
|
||||
for (const entry of entries) {
|
||||
await db.prepare("run", 'DELETE FROM "lockCategories" WHERE "videoID" = ? AND "category" = ?', [videoID, entry.category]);
|
||||
await db.prepare(
|
||||
"run",
|
||||
'DELETE FROM "lockCategories" WHERE "videoID" = ? AND "service" = ? AND "category" = ?',
|
||||
[videoID, service, entry.category]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user