Fix resource leak with http request response body & fix docker file (#16)

* 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
This commit is contained in:
Ward 2024-04-28 00:30:35 +12:00 committed by GitHub
parent 4d364ec4fc
commit a6ec5b17e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 7 deletions

View file

@ -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
main.go
View file

@ -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")
@ -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
}
@ -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
}