mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-15 16:07:03 +03:00
getLockCategories + lint
This commit is contained in:
@@ -45,7 +45,7 @@ import { youtubeApiProxy } from "./routes/youtubeApiProxy";
|
||||
import { getChapterNames } from "./routes/getChapterNames";
|
||||
import { postRating } from "./routes/ratings/postRating";
|
||||
import { getRating } from "./routes/ratings/getRating";
|
||||
import { postClearCache as ratingPostClearCache } from "./routes/ratings/postClearCache"
|
||||
import { postClearCache as ratingPostClearCache } from "./routes/ratings/postClearCache";
|
||||
import { getTopCategoryUsers } from "./routes/getTopCategoryUsers";
|
||||
import { addUserAsTempVIP } from "./routes/addUserAsTempVIP";
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { db } from "../databases/databases";
|
||||
import { Logger } from "../utils/logger";
|
||||
import { Request, Response } from "express";
|
||||
import { hashPrefixTester } from "../utils/hashPrefixTester";
|
||||
import { Category, VideoID, VideoIDHash } from "../types/segments.model";
|
||||
import { ActionType, Category, VideoID, VideoIDHash } from "../types/segments.model";
|
||||
|
||||
interface LockResultByHash {
|
||||
videoID: VideoID,
|
||||
@@ -16,11 +16,13 @@ interface DBLock {
|
||||
hash: VideoIDHash,
|
||||
category: Category,
|
||||
reason: string,
|
||||
actionType: ActionType,
|
||||
}
|
||||
|
||||
const mergeLocks = (source: DBLock[]) => {
|
||||
const mergeLocks = (source: DBLock[], actionTypes: ActionType[]) => {
|
||||
const dest: LockResultByHash[] = [];
|
||||
for (const obj of source) {
|
||||
if (!actionTypes.includes(obj.actionType)) continue;
|
||||
// videoID already exists
|
||||
const destMatch = dest.find(s => s.videoID === obj.videoID);
|
||||
if (destMatch) {
|
||||
@@ -42,6 +44,7 @@ const mergeLocks = (source: DBLock[]) => {
|
||||
|
||||
export async function getLockCategoriesByHash(req: Request, res: Response): Promise<Response> {
|
||||
let hashPrefix = req.params.prefix as VideoIDHash;
|
||||
const actionTypes = req.query.actionTypes as ActionType[] || [ActionType.Mute, ActionType.Skip];
|
||||
if (!hashPrefixTester(req.params.prefix)) {
|
||||
return res.status(400).send("Hash prefix does not match format requirements."); // Exit early on faulty prefix
|
||||
}
|
||||
@@ -49,10 +52,10 @@ export async function getLockCategoriesByHash(req: Request, res: Response): Prom
|
||||
|
||||
try {
|
||||
// Get existing lock categories markers
|
||||
const lockedRows = await db.prepare("all", 'SELECT "videoID", "hashedVideoID" as "hash", "category", "reason" from "lockCategories" where "hashedVideoID" LIKE ?', [`${hashPrefix}%`]) as DBLock[];
|
||||
const lockedRows = await db.prepare("all", 'SELECT "videoID", "hashedVideoID" as "hash", "category", "reason", "actionType" from "lockCategories" where "hashedVideoID" LIKE ?', [`${hashPrefix}%`]) as DBLock[];
|
||||
if (lockedRows.length === 0 || !lockedRows[0]) return res.sendStatus(404);
|
||||
// merge all locks
|
||||
return res.send(mergeLocks(lockedRows));
|
||||
return res.send(mergeLocks(lockedRows, actionTypes));
|
||||
} catch (err) {
|
||||
Logger.error(err as string);
|
||||
return res.sendStatus(500);
|
||||
|
||||
Reference in New Issue
Block a user