Добавлены обработчики для Legacy запросов

This commit is contained in:
ErickSkrauch 2016-07-07 13:10:39 +03:00
parent e3f744ed10
commit 4da7a566f7
4 changed files with 70 additions and 0 deletions

25
lib/routes/Cape.go Normal file
View File

@ -0,0 +1,25 @@
package routes
import (
"net/http"
"github.com/gorilla/mux"
"elyby/minecraft-skinsystem/lib/tools"
)
func Cape(w http.ResponseWriter, r *http.Request) {
username := tools.ParseUsername(mux.Vars(r)["username"])
http.Redirect(w, r, "http://skins.minecraft.net/MinecraftCloaks/" + username + ".png", 301)
}
func CapeGET(w http.ResponseWriter, r *http.Request) {
username := r.URL.Query().Get("name")
if username == "" {
w.WriteHeader(http.StatusBadRequest)
return
}
mux.Vars(r)["username"] = username
Cape(w, r)
}

View File

@ -0,0 +1,28 @@
package routes
import (
"net/http"
"github.com/gorilla/mux"
)
// Метод-наследие от первой версии системы скинов.
// Всё ещё иногда используется
// Просто конвертируем данные и отправляем их в основной обработчик
func MinecraftPHP(w http.ResponseWriter, r *http.Request) {
username := r.URL.Query().Get("name")
required := r.URL.Query().Get("type")
if username == "" || required == "" {
w.WriteHeader(http.StatusBadRequest)
return
}
mux.Vars(r)["username"] = username
switch required {
case "skin": Skin(w, r)
case "cloack": Cape(w, r)
default: {
w.WriteHeader(http.StatusNotFound)
}
}
}

View File

@ -22,3 +22,14 @@ func Skin(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, rec.Url, 301);
}
func SkinGET(w http.ResponseWriter, r *http.Request) {
username := r.URL.Query().Get("name")
if username == "" {
w.WriteHeader(http.StatusBadRequest)
return
}
mux.Vars(r)["username"] = username
Skin(w, r)
}

View File

@ -23,7 +23,13 @@ func main() {
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/", routes.NotFound)
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")
// Legacy
router.HandleFunc("/minecraft.php", routes.MinecraftPHP).Methods("GET")
router.HandleFunc("/skins/", routes.SkinGET).Methods("GET")
router.HandleFunc("/cloaks/", routes.CapeGET).Methods("GET")
// TODO: убрать этого, т.к. он стар
router.HandleFunc("/system/setSkin", routes.SetSkin).Methods("POST")