2016-07-05 03:58:09 +05:30
|
|
|
package routes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
2016-07-06 03:55:05 +05:30
|
|
|
"net/http"
|
2016-07-05 03:58:09 +05:30
|
|
|
"encoding/json"
|
2016-07-06 03:55:05 +05:30
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
|
|
|
|
"elyby/minecraft-skinsystem/lib/data"
|
2016-07-05 03:58:09 +05:30
|
|
|
"elyby/minecraft-skinsystem/lib/tools"
|
2016-09-22 22:02:00 +05:30
|
|
|
"elyby/minecraft-skinsystem/lib/services"
|
2016-07-05 03:58:09 +05:30
|
|
|
)
|
|
|
|
|
2016-07-06 03:55:05 +05:30
|
|
|
func Textures(w http.ResponseWriter, r *http.Request) {
|
2016-08-27 00:38:53 +05:30
|
|
|
services.Stats.Incr("textures-requests", 1)
|
2016-07-05 03:58:09 +05:30
|
|
|
username := tools.ParseUsername(mux.Vars(r)["username"])
|
|
|
|
log.Println("request textures for username " + username)
|
|
|
|
|
2016-09-22 22:02:00 +05:30
|
|
|
rec, err := data.FindSkinByUsername(username)
|
2016-07-05 03:58:09 +05:30
|
|
|
if (err != nil || rec.SkinId == 0) {
|
|
|
|
rec.Url = "http://skins.minecraft.net/MinecraftSkins/" + username + ".png"
|
|
|
|
rec.Hash = string(tools.BuildNonElyTexturesHash(username))
|
2016-07-29 03:50:09 +05:30
|
|
|
} else {
|
|
|
|
rec.Url = tools.BuildElyUrl(rec.Url)
|
2016-07-05 03:58:09 +05:30
|
|
|
}
|
|
|
|
|
2016-07-06 03:55:05 +05:30
|
|
|
textures := data.TexturesResponse{
|
|
|
|
Skin: &data.Skin{
|
2016-07-29 03:50:09 +05:30
|
|
|
Url: rec.Url,
|
2016-07-05 03:58:09 +05:30
|
|
|
Hash: rec.Hash,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rec.IsSlim) {
|
2016-07-06 03:55:05 +05:30
|
|
|
textures.Skin.Metadata = &data.SkinMetadata{
|
2016-07-05 03:58:09 +05:30
|
|
|
Model: "slim",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-22 22:02:00 +05:30
|
|
|
capeRec, err := data.FindCapeByUsername(username)
|
|
|
|
if (err == nil) {
|
|
|
|
capeUrl, err := services.Router.Get("cloaks").URL("username", username)
|
|
|
|
if (err != nil) {
|
|
|
|
log.Println(err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
var scheme string = "http://";
|
|
|
|
if (r.TLS != nil) {
|
|
|
|
scheme = "https://"
|
|
|
|
}
|
|
|
|
|
|
|
|
textures.Cape = &data.Cape{
|
|
|
|
Url: scheme + r.Host + capeUrl.String(),
|
|
|
|
Hash: capeRec.CalculateHash(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-05 03:58:09 +05:30
|
|
|
response,_ := json.Marshal(textures)
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
w.Write(response)
|
|
|
|
}
|