feat: add support for videoId query flags (#15)

This commit is contained in:
Ward 2024-04-26 06:00:15 +12:00 committed by GitHub
parent c7a6438110
commit ee03c20c98
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 4 deletions

View file

@ -10,9 +10,15 @@ IPs are rotated every 2 minutes to avoid rate limiting.
## Example Request ## 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} {"id":"dQw4w9WgXcQ","dateCreated":"2022-04-09T22:01:38.222268Z","likes":14589269,"dislikes":390375,"rating":4.8957585373858015,"viewCount":1232906190,"deleted":false}
``` ```

15
main.go
View file

@ -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")) 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") 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)) match, _ := regexp.Match("^([a-zA-Z0-9_-]{11})", []byte(videoId))
if !match { if !match {