Skip to content

Commit

Permalink
Fix resource leak with http request response body & fix docker file (#16
Browse files Browse the repository at this point in the history
)

* Add support for videoId query flags

* Update README examples

* Fix resource leak

* Close body on 429 & fix docker file with use of fiber prefork

* Add dumb-init to line 12
  • Loading branch information
WardPearce committed Apr 27, 2024
1 parent 4d364ec commit a6ec5b1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ RUN --mount=type=cache,target=/root/.cache/go-build \

FROM alpine

RUN apk --no-cache add --no-check-certificate ca-certificates \
RUN apk --no-cache add --no-check-certificate ca-certificates dumb-init \
&& update-ca-certificates


COPY --from=build /app/main /ryd-proxy

ENTRYPOINT ["/usr/bin/dumb-init", "--"]

EXPOSE 3000
CMD [ "/ryd-proxy" ]
CMD "/ryd-proxy"
13 changes: 8 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func getVotes(c *fiber.Ctx, videoId string) error {
return c.Status(400).SendString("Invalid video id")
}

for true {
for {
req, _ := http.NewRequest("GET", "https://returnyoutubedislikeapi.com/Votes?videoId="+videoId+"&likeCount=", nil)

req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0")
Expand All @@ -91,7 +91,13 @@ func getVotes(c *fiber.Ctx, videoId string) error {

resp, err := client.Do(req)

if err != nil || resp.StatusCode == 429 {
if err != nil {
continue
}

defer resp.Body.Close()

if resp.StatusCode == 429 {
continue
}

Expand All @@ -109,7 +115,4 @@ func getVotes(c *fiber.Ctx, videoId string) error {

return c.Status(resp.StatusCode).SendStream(stream)
}

// Should never be reached
return nil
}

0 comments on commit a6ec5b1

Please sign in to comment.