mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-07 12:07:07 +03:00
use .reduce from @HaiDang666
This commit is contained in:
@@ -14,16 +14,14 @@ export async function getLockCategories(req: Request, res: Response): Promise<Re
|
|||||||
try {
|
try {
|
||||||
// Get existing lock categories markers
|
// Get existing lock categories markers
|
||||||
const row = await db.prepare('all', 'SELECT "category", "reason" from "lockCategories" where "videoID" = ?', [videoID]) as {category: Category, reason: string}[];
|
const row = await db.prepare('all', 'SELECT "category", "reason" from "lockCategories" where "videoID" = ?', [videoID]) as {category: Category, reason: string}[];
|
||||||
// map to array in JS becaues of SQL incompatibilities
|
// map categories to array in JS becaues of SQL incompatibilities
|
||||||
const categories = row.map(item => item.category);
|
const categories = row.map(item => item.category);
|
||||||
if (categories.length === 0 || !categories[0]) return res.sendStatus(404);
|
if (categories.length === 0 || !categories[0]) return res.sendStatus(404);
|
||||||
// Get existing lock categories markers
|
// Get longest lock reason
|
||||||
const reasons = row.map(item => item.reason);
|
const reason = row.map(item => item.reason)
|
||||||
let longReason = "";
|
.reduce((a,b) => (a.length > b.length) ? a : b);
|
||||||
// set longReason if current length is longer
|
|
||||||
reasons.forEach((e) => { if (e.length > longReason.length) longReason = e; });
|
|
||||||
return res.send({
|
return res.send({
|
||||||
reason: longReason,
|
reason,
|
||||||
categories
|
categories
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user