Skip to content

Commit

Permalink
Add endpoint to get segment ID
Browse files Browse the repository at this point in the history
  • Loading branch information
ajayyy committed Jan 18, 2025
1 parent be9d97a commit fa29cfd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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);

Expand Down
20 changes: 20 additions & 0 deletions src/routes/getSegmentID.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { db } from "../databases/databases";
import { Request, Response } from "express";

export async function getSegmentID(req: Request, res: Response): Promise<Response> {
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);
}
}

0 comments on commit fa29cfd

Please sign in to comment.