From ee03c20c9872374557af451cb1e71808b8106490 Mon Sep 17 00:00:00 2001 From: Ward Date: Fri, 26 Apr 2024 06:00:15 +1200 Subject: [PATCH] feat: add support for videoId query flags (#15) --- README.md | 10 ++++++++-- main.go | 15 +++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 249e14d..4657af2 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,15 @@ IPs are rotated every 2 minutes to avoid rate limiting. ## Example Request -https://ryd-proxy.kavin.rocks/votes/dQw4w9WgXcQ +### GET - `/votes/dQw4w9WgXcQ` -```js +```json +{"id":"dQw4w9WgXcQ","dateCreated":"2022-04-09T22:01:38.222268Z","likes":14589269,"dislikes":390375,"rating":4.8957585373858015,"viewCount":1232906190,"deleted":false} +``` + +### GET - `/votes?videoId=dQw4w9WgXcQ` + +```json {"id":"dQw4w9WgXcQ","dateCreated":"2022-04-09T22:01:38.222268Z","likes":14589269,"dislikes":390375,"rating":4.8957585373858015,"viewCount":1232906190,"deleted":false} ``` diff --git a/main.go b/main.go index ace9222..152c11b 100644 --- a/main.go +++ b/main.go @@ -51,15 +51,26 @@ func main() { }, ) - app.Get("/votes/:videoId", handler) + // Route for /votes?videoId=:videoId + app.Get("/votes", handleQuery) + + // Route for /votes/:videoId + app.Get("/votes/:videoId", handleParam) log.Fatal(app.Listen(":3000")) } -func handler(c *fiber.Ctx) error { +func handleQuery(c *fiber.Ctx) error { + videoId := c.Query("videoId") + return getVotes(c, videoId) +} +func handleParam(c *fiber.Ctx) error { videoId := c.Params("videoId") + return getVotes(c, videoId) +} +func getVotes(c *fiber.Ctx, videoId string) error { match, _ := regexp.Match("^([a-zA-Z0-9_-]{11})", []byte(videoId)) if !match {