Rewrite to use external modules

This commit is contained in:
Jacob Gunther
2022-03-18 15:21:20 -05:00
parent 061779f6f3
commit baed581d69
30 changed files with 681 additions and 1323 deletions

View File

@@ -12,9 +12,9 @@ import (
func SkinHandler(ctx *fasthttp.RequestCtx) {
user := ctx.UserValue("user").(string)
download := ctx.QueryArgs().GetBool("download")
opts := util.ParseQueryParams(ctx, config.Routes.RawSkin)
uuid, err := util.GetUUID(user)
uuid, ok, err := util.LookupUUID(user)
if err != nil {
log.Println(err)
@@ -25,7 +25,14 @@ func SkinHandler(ctx *fasthttp.RequestCtx) {
return
}
skin, slim, err := util.GetPlayerSkin(uuid)
if !ok && !opts.Fallback {
ctx.SetStatusCode(http.StatusNotFound)
ctx.SetBodyString(http.StatusText(http.StatusNotFound))
return
}
rawSkin, _, err := util.GetPlayerSkin(uuid)
if err != nil {
log.Println(err)
@@ -36,11 +43,7 @@ func SkinHandler(ctx *fasthttp.RequestCtx) {
return
}
if skin == nil {
skin = util.GetDefaultSkin(slim)
}
data, err := util.EncodePNG(skin)
data, err := util.EncodePNG(rawSkin)
if err != nil {
log.Println(err)
@@ -51,7 +54,7 @@ func SkinHandler(ctx *fasthttp.RequestCtx) {
return
}
if download {
if opts.Download {
ctx.Response.Header.Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s.png"`, user))
}