From fa29cfd3c65f83e2bf5689dc160ed2fb18ffc94e Mon Sep 17 00:00:00 2001 From: Ajay Date: Sat, 18 Jan 2025 02:56:57 -0500 Subject: [PATCH] Add endpoint to get segment ID --- src/app.ts | 3 +++ src/routes/getSegmentID.ts | 20 ++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/routes/getSegmentID.ts diff --git a/src/app.ts b/src/app.ts index 6e85b673..374dfb7d 100644 --- a/src/app.ts +++ b/src/app.ts @@ -58,6 +58,7 @@ import { getTopBrandingUsers } from "./routes/getTopBrandingUsers"; import { getFeatureFlag } from "./routes/getFeatureFlag"; import { getReady } from "./routes/getReady"; import { getMetrics } from "./routes/getMetrics"; +import { getSegmentID } from "./routes/getSegmentID"; export function createServer(callback: () => void): Server { // Create a service (the app object is just a callback). @@ -122,6 +123,8 @@ function setupRoutes(router: Router, server: Server) { router.get("/api/viewedVideoSponsorTime", ...viewEndpoints); router.post("/api/viewedVideoSponsorTime", ...viewEndpoints); + router.get("/api/segmentID", getSegmentID); + //To set your username for the stats view router.post("/api/setUsername", setUsername); diff --git a/src/routes/getSegmentID.ts b/src/routes/getSegmentID.ts new file mode 100644 index 00000000..b65800e9 --- /dev/null +++ b/src/routes/getSegmentID.ts @@ -0,0 +1,20 @@ +import { db } from "../databases/databases"; +import { Request, Response } from "express"; + +export async function getSegmentID(req: Request, res: Response): Promise { + const partialUUID = req.query?.UUID; + const videoID = req.query?.videoID; + + if (!partialUUID || !videoID) { + //invalid request + return res.sendStatus(400); + } + + const data = await db.prepare("get", `SELECT "UUID" from "sponsorTimes" WHERE "UUID" LIKE ? AND "videoID" = ?`, [`${partialUUID}%`, videoID]); + + if (data) { + return res.status(200).send(data.UUID); + } else { + return res.sendStatus(404); + } +}