mirror of
https://github.com/elyby/chrly.git
synced 2024-11-27 01:01:59 +05:30
04714543b8
Упразднён пакет utils. Удалён обработчик minecraft.php (legacy с самого-самого начала Ely.by) Добавлены тесты для всех api-запросов.
37 lines
930 B
Go
37 lines
930 B
Go
package http
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
)
|
|
|
|
func (cfg *Config) Skin(response http.ResponseWriter, request *http.Request) {
|
|
if mux.Vars(request)["converted"] == "" {
|
|
cfg.Logger.IncCounter("skins.request", 1)
|
|
}
|
|
|
|
username := parseUsername(mux.Vars(request)["username"])
|
|
rec, err := cfg.SkinsRepo.FindByUsername(username)
|
|
if err != nil || rec.SkinId == 0 {
|
|
http.Redirect(response, request, "http://skins.minecraft.net/MinecraftSkins/" + username + ".png", 301)
|
|
return
|
|
}
|
|
|
|
http.Redirect(response, request, buildElyUrl(rec.Url), 301)
|
|
}
|
|
|
|
func (cfg *Config) SkinGET(response http.ResponseWriter, request *http.Request) {
|
|
cfg.Logger.IncCounter("skins.get_request", 1)
|
|
username := request.URL.Query().Get("name")
|
|
if username == "" {
|
|
response.WriteHeader(http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
mux.Vars(request)["username"] = username
|
|
mux.Vars(request)["converted"] = "1"
|
|
|
|
cfg.Skin(response, request)
|
|
}
|