Add initial code
This commit is contained in:
60
src/routes/skin.go
Normal file
60
src/routes/skin.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"main/src/util"
|
||||
"net/http"
|
||||
|
||||
"github.com/valyala/fasthttp"
|
||||
)
|
||||
|
||||
func SkinHandler(ctx *fasthttp.RequestCtx) {
|
||||
user := ctx.UserValue("user").(string)
|
||||
|
||||
download := ctx.QueryArgs().GetBool("download")
|
||||
|
||||
uuid, err := util.GetUUID(r, user)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
|
||||
ctx.SetStatusCode(http.StatusInternalServerError)
|
||||
ctx.SetBodyString(http.StatusText(http.StatusInternalServerError))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
skin, slim, err := util.GetPlayerSkin(r, uuid)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
|
||||
ctx.SetStatusCode(http.StatusInternalServerError)
|
||||
ctx.SetBodyString(http.StatusText(http.StatusInternalServerError))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if skin == nil {
|
||||
skin = util.GetDefaultSkin(slim)
|
||||
}
|
||||
|
||||
data, err := util.EncodePNG(skin)
|
||||
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
|
||||
ctx.SetStatusCode(http.StatusInternalServerError)
|
||||
ctx.SetBodyString(http.StatusText(http.StatusInternalServerError))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if download {
|
||||
ctx.Response.Header.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s.png"`, user))
|
||||
}
|
||||
|
||||
ctx.SetContentType("image/png")
|
||||
ctx.SetBody(data)
|
||||
}
|
||||
Reference in New Issue
Block a user