mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-25 17:08:35 +03:00
Merge branch 'master' of https://github.com/ajayyy/SponsorBlockServer into stricter-eslint
This commit is contained in:
@@ -13,11 +13,15 @@ export async function getLockCategories(req: Request, res: Response): Promise<Re
|
||||
|
||||
try {
|
||||
// Get existing lock categories markers
|
||||
const lockedCategories = await db.prepare("all", 'SELECT "category" from "lockCategories" where "videoID" = ?', [videoID]) as {category: Category}[];
|
||||
if (lockedCategories.length === 0 || !lockedCategories[0]) return res.sendStatus(404);
|
||||
// map to array in JS becaues of SQL incompatibilities
|
||||
const categories = Object.values(lockedCategories).map((entry) => entry.category);
|
||||
const row = await db.prepare("all", 'SELECT "category", "reason" from "lockCategories" where "videoID" = ?', [videoID]) as {category: Category, reason: string}[];
|
||||
// map categories to array in JS becaues of SQL incompatibilities
|
||||
const categories = row.map(item => item.category);
|
||||
if (categories.length === 0 || !categories[0]) return res.sendStatus(404);
|
||||
// Get longest lock reason
|
||||
const reason = row.map(item => item.reason)
|
||||
.reduce((a,b) => (a.length > b.length) ? a : b);
|
||||
return res.send({
|
||||
reason,
|
||||
categories
|
||||
});
|
||||
} catch (err) {
|
||||
|
||||
@@ -7,13 +7,15 @@ import { Category, VideoID, VideoIDHash } from "../types/segments.model";
|
||||
interface LockResultByHash {
|
||||
videoID: VideoID,
|
||||
hash: VideoIDHash,
|
||||
reason: string,
|
||||
categories: Category[]
|
||||
}
|
||||
|
||||
interface DBLock {
|
||||
videoID: VideoID,
|
||||
hash: VideoIDHash,
|
||||
category: Category
|
||||
category: Category,
|
||||
reason: string,
|
||||
}
|
||||
|
||||
const mergeLocks = (source: DBLock[]) => {
|
||||
@@ -22,12 +24,15 @@ const mergeLocks = (source: DBLock[]) => {
|
||||
// videoID already exists
|
||||
const destMatch = dest.find(s => s.videoID === obj.videoID);
|
||||
if (destMatch) {
|
||||
// override longer reason
|
||||
if (obj.reason.length > destMatch.reason.length) destMatch.reason = obj.reason;
|
||||
// push to categories
|
||||
destMatch.categories.push(obj.category);
|
||||
} else {
|
||||
dest.push({
|
||||
videoID: obj.videoID,
|
||||
hash: obj.hash,
|
||||
reason: obj.reason,
|
||||
categories: [obj.category]
|
||||
});
|
||||
}
|
||||
|
||||
@@ -275,6 +275,10 @@ async function chooseSegments(segments: DBSegment[], max: number): Promise<DBSeg
|
||||
*/
|
||||
async function handleGetSegments(req: Request, res: Response): Promise<Segment[] | false> {
|
||||
const videoID = req.query.videoID as VideoID;
|
||||
if (!videoID) {
|
||||
res.status(400).send("videoID not specified");
|
||||
return false;
|
||||
}
|
||||
// Default to sponsor
|
||||
// If using params instead of JSON, only one category can be pulled
|
||||
const categories: Category[] = req.query.categories
|
||||
|
||||
@@ -5,7 +5,7 @@ import { ActionType, Category, SegmentUUID, Service, VideoIDHash } from "../type
|
||||
|
||||
export async function getSkipSegmentsByHash(req: Request, res: Response): Promise<Response> {
|
||||
let hashPrefix = req.params.prefix as VideoIDHash;
|
||||
if (!hashPrefixTester(req.params.prefix)) {
|
||||
if (!req.params.prefix || !hashPrefixTester(req.params.prefix)) {
|
||||
return res.status(400).send("Hash prefix does not match format requirements."); // Exit early on faulty prefix
|
||||
}
|
||||
hashPrefix = hashPrefix.toLowerCase() as VideoIDHash;
|
||||
|
||||
@@ -6,6 +6,8 @@ import {getHash} from "../utils/getHash";
|
||||
import { HashedUserID, UserID } from "../types/user.model";
|
||||
|
||||
export async function postWarning(req: Request, res: Response): Promise<Response> {
|
||||
// exit early if no body passed in
|
||||
if (!req.body.userID && !req.body.issuerUserID) return res.status(400).json({"message": "Missing parameters"});
|
||||
// Collect user input data
|
||||
const issuerUserID: HashedUserID = getHash(<UserID> req.body.issuerUserID);
|
||||
const userID: UserID = req.body.userID;
|
||||
|
||||
Reference in New Issue
Block a user