From ee03c20c9872374557af451cb1e71808b8106490 Mon Sep 17 00:00:00 2001 From: Ward Date: Fri, 26 Apr 2024 06:00:15 +1200 Subject: [PATCH 1/2] 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 { From 4d364ec4fc4580cc50516de61746e96e8419a575 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 26 Apr 2024 11:27:10 +0200 Subject: [PATCH 2/2] ci: switch to alpine base image (see #15) --- Dockerfile | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4ac5023..c63f5bb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:latest AS build +FROM golang:alpine AS build WORKDIR /app/ @@ -7,15 +7,13 @@ COPY . . RUN --mount=type=cache,target=/root/.cache/go-build \ go build -ldflags "-s -w" main.go -FROM debian:stable-slim +FROM alpine -RUN apt-get update && apt-get install -y --no-install-recommends \ - ca-certificates \ - && rm -rf /var/lib/apt/lists/* +RUN apk --no-cache add --no-check-certificate ca-certificates \ + && update-ca-certificates -WORKDIR /app/ -COPY --from=build /app/main /app/ryd-proxy +COPY --from=build /app/main /ryd-proxy EXPOSE 3000 -CMD ./ryd-proxy +CMD [ "/ryd-proxy" ]