2016-07-05 03:58:09 +05:30
|
|
|
package routes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2016-07-06 03:55:05 +05:30
|
|
|
|
2016-07-05 03:58:09 +05:30
|
|
|
"github.com/gorilla/mux"
|
2016-07-06 03:55:05 +05:30
|
|
|
|
2016-07-05 03:58:09 +05:30
|
|
|
"elyby/minecraft-skinsystem/lib/tools"
|
2016-07-06 03:55:05 +05:30
|
|
|
"elyby/minecraft-skinsystem/lib/data"
|
2016-12-03 04:27:55 +05:30
|
|
|
"elyby/minecraft-skinsystem/lib/services"
|
2016-07-05 03:58:09 +05:30
|
|
|
)
|
|
|
|
|
2016-07-06 03:55:05 +05:30
|
|
|
func Skin(w http.ResponseWriter, r *http.Request) {
|
2016-12-03 04:27:55 +05:30
|
|
|
if (mux.Vars(r)["converted"] == "") {
|
|
|
|
services.Logger.IncCounter("skins.request", 1)
|
|
|
|
}
|
|
|
|
|
2016-07-05 03:58:09 +05:30
|
|
|
username := tools.ParseUsername(mux.Vars(r)["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) {
|
|
|
|
http.Redirect(w, r, "http://skins.minecraft.net/MinecraftSkins/" + username + ".png", 301)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-07-29 03:43:09 +05:30
|
|
|
http.Redirect(w, r, tools.BuildElyUrl(rec.Url), 301);
|
2016-07-05 03:58:09 +05:30
|
|
|
}
|
2016-07-07 15:40:39 +05:30
|
|
|
|
|
|
|
func SkinGET(w http.ResponseWriter, r *http.Request) {
|
2016-12-03 04:27:55 +05:30
|
|
|
services.Logger.IncCounter("skins.get-request", 1)
|
2016-07-07 15:40:39 +05:30
|
|
|
username := r.URL.Query().Get("name")
|
|
|
|
if username == "" {
|
|
|
|
w.WriteHeader(http.StatusBadRequest)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
mux.Vars(r)["username"] = username
|
2016-12-03 04:27:55 +05:30
|
|
|
mux.Vars(r)["converted"] = "1"
|
2016-07-07 15:40:39 +05:30
|
|
|
Skin(w, r)
|
|
|
|
}
|