0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch-backend.git synced 2025-01-03 11:20:08 -05:00
safetwitch-backend/routes/proxy/proxy.go
2023-05-22 18:11:58 -04:00

31 lines
690 B
Go

package proxy
import (
b64 "encoding/base64"
"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)
}
reader := imageResp.Body
contentLength := imageResp.ContentLength
contentType := imageResp.Header.Get("Content-Type")
context.DataFromReader(200, contentLength, contentType, reader, map[string]string{})
context.JSON(imageResp.StatusCode, imageResp.Body)
})
}