Корректировка под более-менее финальную версию протокола

This commit is contained in:
ErickSkrauch 2016-07-29 01:13:09 +03:00
parent c2d0cb93cb
commit 64bf7deb79
6 changed files with 10 additions and 9 deletions

View File

@ -10,7 +10,7 @@ import (
type SkinItem struct { type SkinItem struct {
UserId int `json:"userId"` UserId int `json:"userId"`
Nickname string `json:"nickname"` Username string `json:"username"`
SkinId int `json:"skinId"` SkinId int `json:"skinId"`
Url string `json:"url"` Url string `json:"url"`
Is1_8 bool `json:"is1_8"` Is1_8 bool `json:"is1_8"`
@ -20,7 +20,7 @@ type SkinItem struct {
func (s *SkinItem) Save() { func (s *SkinItem) Save() {
str, _ := json.Marshal(s) 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) { func FindRecord(username string) (SkinItem, error) {

View File

@ -2,7 +2,6 @@ package routes
import ( import (
"net/http" "net/http"
"strings"
"strconv" "strconv"
"elyby/minecraft-skinsystem/lib/data" "elyby/minecraft-skinsystem/lib/data"
@ -17,7 +16,7 @@ func SetSkin(w http.ResponseWriter, r *http.Request) {
} }
skin := new(data.SkinItem) skin := new(data.SkinItem)
skin.Nickname = strings.ToLower(r.PostFormValue("nickname")) skin.Username = r.PostFormValue("username")
skin.UserId, _ = strconv.Atoi(r.PostFormValue("userId")) skin.UserId, _ = strconv.Atoi(r.PostFormValue("userId"))
skin.SkinId, _ = strconv.Atoi(r.PostFormValue("skinId")) skin.SkinId, _ = strconv.Atoi(r.PostFormValue("skinId"))
skin.Hash = r.PostFormValue("hash") skin.Hash = r.PostFormValue("hash")

View File

@ -20,7 +20,7 @@ func Skin(w http.ResponseWriter, r *http.Request) {
return 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) { func SkinGET(w http.ResponseWriter, r *http.Request) {

View File

@ -23,7 +23,7 @@ func Textures(w http.ResponseWriter, r *http.Request) {
textures := data.TexturesResponse{ textures := data.TexturesResponse{
Skin: &data.Skin{ Skin: &data.Skin{
Url: rec.Url, Url: tools.BuildElyUrl(rec.Url),
Hash: rec.Hash, Hash: rec.Hash,
}, },
} }

View File

@ -29,7 +29,12 @@ func BuildKey(username string) string {
return "username:" + strings.ToLower(username) return "username:" + strings.ToLower(username)
} }
func BuildElyUrl(route string) string {
return "http://ely.by" + route
}
func getCurrentHour() int64 { func getCurrentHour() int64 {
n := time.Now() n := time.Now()
return time.Date(n.Year(), n.Month(), n.Day(), n.Hour(), 0, 0, 0, time.UTC).Unix() return time.Date(n.Year(), n.Month(), n.Day(), n.Hour(), 0, 0, 0, time.UTC).Unix()
} }

View File

@ -34,9 +34,6 @@ func main() {
// 404 // 404
router.NotFoundHandler = http.HandlerFunc(routes.NotFound) router.NotFoundHandler = http.HandlerFunc(routes.NotFound)
// TODO: убрать этого, т.к. он стар
router.HandleFunc("/system/setSkin", routes.SetSkin).Methods("POST")
apiRouter := router.PathPrefix("/api").Subrouter() apiRouter := router.PathPrefix("/api").Subrouter()
apiRouter.HandleFunc("/user/{username}/skin", routes.SetSkin).Methods("POST") apiRouter.HandleFunc("/user/{username}/skin", routes.SetSkin).Methods("POST")