chrly/http/signed_textures.go

42 lines
991 B
Go
Raw Normal View History

package http
import (
"encoding/json"
"net/http"
"strings"
2019-04-14 20:06:27 +05:30
"github.com/elyby/chrly/api/mojang"
"github.com/gorilla/mux"
)
func (cfg *Config) SignedTextures(response http.ResponseWriter, request *http.Request) {
cfg.Logger.IncCounter("signed_textures.request", 1)
username := parseUsername(mux.Vars(request)["username"])
rec, err := cfg.SkinsRepo.FindByUsername(username)
if err != nil || rec.SkinId == 0 || rec.MojangTextures == "" {
response.WriteHeader(http.StatusNoContent)
return
}
2019-04-14 20:06:27 +05:30
responseData := mojang.SignedTexturesResponse{
Id: strings.Replace(rec.Uuid, "-", "", -1),
Name: rec.Username,
2019-04-21 23:05:35 +05:30
Props: []*mojang.Property{
{
2019-04-14 20:06:27 +05:30
Name: "textures",
Signature: rec.MojangSignature,
2019-04-14 20:06:27 +05:30
Value: rec.MojangTextures,
},
{
2019-04-14 20:06:27 +05:30
Name: "chrly",
2018-02-11 19:33:13 +05:30
Value: "how do you tame a horse in Minecraft?",
},
},
}
2019-04-14 20:06:27 +05:30
responseJson, _ := json.Marshal(responseData)
response.Header().Set("Content-Type", "application/json")
response.Write(responseJson)
}