0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch-backend.git synced 2025-01-08 13:50:05 -05:00
safetwitch-backend/routes/proxy/proxy.go

35 lines
664 B
Go
Raw Normal View History

2023-05-22 17:11:58 -05:00
package proxy
import (
b64 "encoding/base64"
2023-05-31 18:36:57 -05:00
"io"
2023-05-22 17:11:58 -05:00
"net/http"
"github.com/gin-gonic/gin"
)
func Routes(route *gin.Engine) {
auth := route.Group("/proxy")
auth.GET("/img/:url", func(context *gin.Context) {
decodedUrl, err := b64.StdEncoding.DecodeString(context.Param("url"))
if err != nil {
context.Error(err)
}
imageResp, err := http.Get(string(decodedUrl))
if err != nil {
context.Error(err)
}
2023-05-31 18:36:57 -05:00
body, err := io.ReadAll(imageResp.Body)
if err != nil {
context.Error(err)
}
2023-05-22 17:11:58 -05:00
contentType := imageResp.Header.Get("Content-Type")
2023-05-31 18:36:57 -05:00
context.Data(200, contentType, body)
2023-05-22 17:11:58 -05:00
context.JSON(imageResp.StatusCode, imageResp.Body)
})
}