mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 01:02:30 +01:00
Add leaderboard for dearrow
This commit is contained in:
parent
d1d2b011f8
commit
d030de83bd
2 changed files with 45 additions and 0 deletions
|
@ -54,6 +54,7 @@ import { postBranding } from "./routes/postBranding";
|
|||
import { cacheMiddlware } from "./middleware/etag";
|
||||
import { hostHeader } from "./middleware/hostHeader";
|
||||
import { getBrandingStats } from "./routes/getBrandingStats";
|
||||
import { getTopBrandingUsers } from "./routes/getTopBrandingUsers";
|
||||
|
||||
export function createServer(callback: () => void): Server {
|
||||
// Create a service (the app object is just a callback).
|
||||
|
@ -141,6 +142,7 @@ function setupRoutes(router: Router) {
|
|||
|
||||
router.get("/api/getTopUsers", getTopUsers);
|
||||
router.get("/api/getTopCategoryUsers", getTopCategoryUsers);
|
||||
router.get("/api/getTopBrandingUsers", getTopBrandingUsers);
|
||||
|
||||
//send out totals
|
||||
//send the total submissions, total views and total minutes saved
|
||||
|
|
43
src/routes/getTopBrandingUsers.ts
Normal file
43
src/routes/getTopBrandingUsers.ts
Normal file
|
@ -0,0 +1,43 @@
|
|||
import { db } from "../databases/databases";
|
||||
import { Request, Response } from "express";
|
||||
|
||||
async function generateTopUsersStats(sortBy: string) {
|
||||
const rows = await db.prepare("all", `SELECT COUNT(distinct "titles"."UUID") as "titleCount", COUNT(distinct "thumbnails"."UUID") as "thumbnailCount", COALESCE("userName", "titles"."userID") as "userName"
|
||||
FROM "titles"
|
||||
LEFT JOIN "titleVotes" ON "titles"."UUID" = "titleVotes"."UUID"
|
||||
LEFT JOIN "userNames" ON "titles"."userID"="userNames"."userID"
|
||||
LEFT JOIN "thumbnails" ON "titles"."userID" = "thumbnails"."userID"
|
||||
LEFT JOIN "thumbnailVotes" ON "thumbnails"."UUID" = "thumbnailVotes"."UUID"
|
||||
WHERE "titleVotes"."votes" > -1 AND "titleVotes"."shadowHidden" != 1
|
||||
GROUP BY COALESCE("userName", "titles"."userID") HAVING SUM("titleVotes"."votes") > 2 OR SUM("thumbnailVotes"."votes") > 2
|
||||
ORDER BY "${sortBy}" DESC LIMIT 100`, []) as { titleCount: number, thumbnailCount: number, userName: string }[];
|
||||
|
||||
return rows.map((row) => ({
|
||||
userName: row.userName,
|
||||
titles: row.titleCount,
|
||||
thumbnails: row.thumbnailCount
|
||||
}));
|
||||
}
|
||||
|
||||
export async function getTopBrandingUsers(req: Request, res: Response): Promise<Response> {
|
||||
const sortType = parseInt(req.query.sortType as string);
|
||||
|
||||
let sortBy = "";
|
||||
if (sortType == 0) {
|
||||
sortBy = "titleCount";
|
||||
} else if (sortType == 1) {
|
||||
sortBy = "thumbnailCount";
|
||||
} else {
|
||||
//invalid request
|
||||
return res.sendStatus(400);
|
||||
}
|
||||
|
||||
if (db.highLoad()) {
|
||||
return res.status(503).send("Disabled for load reasons");
|
||||
}
|
||||
|
||||
const stats = await generateTopUsersStats(sortBy);
|
||||
|
||||
//send this result
|
||||
return res.send(stats);
|
||||
}
|
Loading…
Reference in a new issue