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-07-06 03:55:05 +05:30
|
|
|
func Textures(w http.ResponseWriter, r *http.Request) {
|
2016-07-05 03:58:09 +05:30
|
|
|
username := tools.ParseUsername(mux.Vars(r)["username"])
|
|
|
|
log.Println("request textures for username " + username)
|
|
|
|
|
2016-07-06 03:55:05 +05:30
|
|
|
rec, err := data.FindRecord(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",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
response,_ := json.Marshal(textures)
|
|
|
|
w.Header().Set("Content-Type", "application/json")
|
|
|
|
w.Write(response)
|
|
|
|
}
|