mirror of
https://github.com/TeamPiped/RYD-Proxy.git
synced 2025-01-06 01:20:37 +05:30
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:
parent
4d364ec4fc
commit
a6ec5b17e4
@ -9,11 +9,13 @@ RUN --mount=type=cache,target=/root/.cache/go-build \
|
|||||||
|
|
||||||
FROM alpine
|
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
|
&& update-ca-certificates
|
||||||
|
|
||||||
|
|
||||||
COPY --from=build /app/main /ryd-proxy
|
COPY --from=build /app/main /ryd-proxy
|
||||||
|
|
||||||
|
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
CMD [ "/ryd-proxy" ]
|
CMD "/ryd-proxy"
|
||||||
|
13
main.go
13
main.go
@ -77,7 +77,7 @@ func getVotes(c *fiber.Ctx, videoId string) error {
|
|||||||
return c.Status(400).SendString("Invalid video id")
|
return c.Status(400).SendString("Invalid video id")
|
||||||
}
|
}
|
||||||
|
|
||||||
for true {
|
for {
|
||||||
req, _ := http.NewRequest("GET", "https://returnyoutubedislikeapi.com/Votes?videoId="+videoId+"&likeCount=", nil)
|
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")
|
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)
|
resp, err := client.Do(req)
|
||||||
|
|
||||||
if err != nil || resp.StatusCode == 429 {
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
if resp.StatusCode == 429 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +115,4 @@ func getVotes(c *fiber.Ctx, videoId string) error {
|
|||||||
|
|
||||||
return c.Status(resp.StatusCode).SendStream(stream)
|
return c.Status(resp.StatusCode).SendStream(stream)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should never be reached
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user