Добавлен роут для загрузки рендера лица скина

This commit is contained in:
ErickSkrauch 2016-09-21 20:52:28 +03:00
parent 0d6ca356d1
commit e03832b4e8
2 changed files with 33 additions and 0 deletions

31
lib/routes/Face.go Normal file
View File

@ -0,0 +1,31 @@
package routes
import (
"log"
"net/http"
"github.com/gorilla/mux"
"elyby/minecraft-skinsystem/lib/tools"
"elyby/minecraft-skinsystem/lib/data"
)
const defaultHash = "default"
func Face(w http.ResponseWriter, r *http.Request) {
username := tools.ParseUsername(mux.Vars(r)["username"])
log.Println("request skin for username " + username);
rec, err := data.FindByUsername(username)
var hash string
if (err != nil || rec.SkinId == 0) {
hash = defaultHash;
} else {
hash = rec.Hash
}
http.Redirect(w, r, tools.BuildElyUrl(buildFaceUrl(hash)), 301);
}
func buildFaceUrl(hash string) string {
return "/minecfaft/skin_buffer/faces/" + hash + ".png"
}

View File

@ -49,6 +49,8 @@ func main() {
router.HandleFunc("/skins/{username}", routes.Skin).Methods("GET").Name("skins")
router.HandleFunc("/cloaks/{username}", routes.Cape).Methods("GET").Name("cloaks")
router.HandleFunc("/textures/{username}", routes.Textures).Methods("GET").Name("textures")
router.HandleFunc("/skins/{username}/face", routes.Face).Methods("GET").Name("faces")
router.HandleFunc("/skins/{username}/face.png", routes.Face).Methods("GET").Name("faces")
// Legacy
router.HandleFunc("/minecraft.php", routes.MinecraftPHP).Methods("GET")
router.HandleFunc("/skins/", routes.SkinGET).Methods("GET")