mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-05-11 02:16:07 +02:00
Add endpoint to get segment ID
This commit is contained in:
parent
be9d97ae2b
commit
fa29cfd3c6
2 changed files with 23 additions and 0 deletions
|
@ -58,6 +58,7 @@ import { getTopBrandingUsers } from "./routes/getTopBrandingUsers";
|
||||||
import { getFeatureFlag } from "./routes/getFeatureFlag";
|
import { getFeatureFlag } from "./routes/getFeatureFlag";
|
||||||
import { getReady } from "./routes/getReady";
|
import { getReady } from "./routes/getReady";
|
||||||
import { getMetrics } from "./routes/getMetrics";
|
import { getMetrics } from "./routes/getMetrics";
|
||||||
|
import { getSegmentID } from "./routes/getSegmentID";
|
||||||
|
|
||||||
export function createServer(callback: () => void): Server {
|
export function createServer(callback: () => void): Server {
|
||||||
// Create a service (the app object is just a callback).
|
// 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.get("/api/viewedVideoSponsorTime", ...viewEndpoints);
|
||||||
router.post("/api/viewedVideoSponsorTime", ...viewEndpoints);
|
router.post("/api/viewedVideoSponsorTime", ...viewEndpoints);
|
||||||
|
|
||||||
|
router.get("/api/segmentID", getSegmentID);
|
||||||
|
|
||||||
//To set your username for the stats view
|
//To set your username for the stats view
|
||||||
router.post("/api/setUsername", setUsername);
|
router.post("/api/setUsername", setUsername);
|
||||||
|
|
||||||
|
|
20
src/routes/getSegmentID.ts
Normal file
20
src/routes/getSegmentID.ts
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue