From 64bf7deb791a27b0170504d9a8b11795de38bfde Mon Sep 17 00:00:00 2001 From: ErickSkrauch Date: Fri, 29 Jul 2016 01:13:09 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B0=20=D0=BF=D0=BE=D0=B4=20?= =?UTF-8?q?=D0=B1=D0=BE=D0=BB=D0=B5=D0=B5-=D0=BC=D0=B5=D0=BD=D0=B5=D0=B5?= =?UTF-8?q?=20=D1=84=D0=B8=D0=BD=D0=B0=D0=BB=D1=8C=D0=BD=D1=83=D1=8E=20?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8E=20=D0=BF=D1=80=D0=BE=D1=82?= =?UTF-8?q?=D0=BE=D0=BA=D0=BE=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/data/SkinItem.go | 4 ++-- lib/routes/SetSkin.go | 3 +-- lib/routes/Skin.go | 2 +- lib/routes/Textures.go | 2 +- lib/tools/tools.go | 5 +++++ minecraft-skinsystem.go | 3 --- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/data/SkinItem.go b/lib/data/SkinItem.go index fdad40a..8fe0f86 100644 --- a/lib/data/SkinItem.go +++ b/lib/data/SkinItem.go @@ -10,7 +10,7 @@ import ( type SkinItem struct { UserId int `json:"userId"` - Nickname string `json:"nickname"` + Username string `json:"username"` SkinId int `json:"skinId"` Url string `json:"url"` Is1_8 bool `json:"is1_8"` @@ -20,7 +20,7 @@ type SkinItem struct { func (s *SkinItem) Save() { str, _ := json.Marshal(s) - services.Redis.Cmd("SET", tools.BuildKey(s.Nickname), str) + services.Redis.Cmd("SET", tools.BuildKey(s.Username), str) } func FindRecord(username string) (SkinItem, error) { diff --git a/lib/routes/SetSkin.go b/lib/routes/SetSkin.go index 897e4c6..b1acb87 100644 --- a/lib/routes/SetSkin.go +++ b/lib/routes/SetSkin.go @@ -2,7 +2,6 @@ package routes import ( "net/http" - "strings" "strconv" "elyby/minecraft-skinsystem/lib/data" @@ -17,7 +16,7 @@ func SetSkin(w http.ResponseWriter, r *http.Request) { } skin := new(data.SkinItem) - skin.Nickname = strings.ToLower(r.PostFormValue("nickname")) + skin.Username = r.PostFormValue("username") skin.UserId, _ = strconv.Atoi(r.PostFormValue("userId")) skin.SkinId, _ = strconv.Atoi(r.PostFormValue("skinId")) skin.Hash = r.PostFormValue("hash") diff --git a/lib/routes/Skin.go b/lib/routes/Skin.go index 9fed97d..ca4f42f 100644 --- a/lib/routes/Skin.go +++ b/lib/routes/Skin.go @@ -20,7 +20,7 @@ func Skin(w http.ResponseWriter, r *http.Request) { return } - http.Redirect(w, r, rec.Url, 301); + http.Redirect(w, r, tools.BuildElyUrl(rec.Url), 301); } func SkinGET(w http.ResponseWriter, r *http.Request) { diff --git a/lib/routes/Textures.go b/lib/routes/Textures.go index 72ac663..b05df03 100644 --- a/lib/routes/Textures.go +++ b/lib/routes/Textures.go @@ -23,7 +23,7 @@ func Textures(w http.ResponseWriter, r *http.Request) { textures := data.TexturesResponse{ Skin: &data.Skin{ - Url: rec.Url, + Url: tools.BuildElyUrl(rec.Url), Hash: rec.Hash, }, } diff --git a/lib/tools/tools.go b/lib/tools/tools.go index 0814856..7e5158b 100644 --- a/lib/tools/tools.go +++ b/lib/tools/tools.go @@ -29,7 +29,12 @@ func BuildKey(username string) string { return "username:" + strings.ToLower(username) } +func BuildElyUrl(route string) string { + return "http://ely.by" + route +} + func getCurrentHour() int64 { n := time.Now() return time.Date(n.Year(), n.Month(), n.Day(), n.Hour(), 0, 0, 0, time.UTC).Unix() } + diff --git a/minecraft-skinsystem.go b/minecraft-skinsystem.go index 044e776..119e522 100644 --- a/minecraft-skinsystem.go +++ b/minecraft-skinsystem.go @@ -34,9 +34,6 @@ func main() { // 404 router.NotFoundHandler = http.HandlerFunc(routes.NotFound) - // TODO: убрать этого, т.к. он стар - router.HandleFunc("/system/setSkin", routes.SetSkin).Methods("POST") - apiRouter := router.PathPrefix("/api").Subrouter() apiRouter.HandleFunc("/user/{username}/skin", routes.SetSkin).Methods("POST")