mirror of
https://codeberg.org/SafeTwitch/safetwitch-backend.git
synced 2024-12-22 05:02:58 -05:00
Add image proxy
This commit is contained in:
parent
129d731a95
commit
d6d820cdc1
2 changed files with 33 additions and 0 deletions
31
routes/proxy/proxy.go
Normal file
31
routes/proxy/proxy.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
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)
|
||||
})
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package routes
|
||||
|
||||
import (
|
||||
"safetwitch-backend/routes/proxy"
|
||||
"safetwitch-backend/routes/users"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
@ -8,4 +9,5 @@ import (
|
|||
|
||||
func SetRoutes(router *gin.Engine) {
|
||||
users.Routes(router)
|
||||
proxy.Routes(router)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue