Merge branch 'master' of https://github.com/ajayyy/SponsorBlockServer into stricter-eslint

This commit is contained in:
Michael C
2021-07-13 15:55:03 -04:00
18 changed files with 145 additions and 48 deletions

View File

@@ -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) {