Removed Ely-specific faces API

This commit is contained in:
ErickSkrauch 2018-02-01 23:16:35 +03:00
parent 6192a58f63
commit ce99ac8cf8
No known key found for this signature in database
GPG Key ID: 669339FCBB30EE0E
3 changed files with 0 additions and 82 deletions

View File

@ -1,27 +0,0 @@
package http
import (
"net/http"
"github.com/gorilla/mux"
)
const defaultHash = "default"
func (cfg *Config) Face(response http.ResponseWriter, request *http.Request) {
cfg.Logger.IncCounter("faces.request", 1)
username := parseUsername(mux.Vars(request)["username"])
rec, err := cfg.SkinsRepo.FindByUsername(username)
var hash string
if err != nil || rec.SkinId == 0 {
hash = defaultHash
} else {
hash = rec.Hash
}
http.Redirect(response, request, buildFaceUrl(hash), 301)
}
func buildFaceUrl(hash string) string {
return "http://ely.by/minecraft/skin_buffer/faces/" + hash + ".png"
}

View File

@ -1,53 +0,0 @@
package http
import (
"net/http/httptest"
"testing"
"github.com/golang/mock/gomock"
testify "github.com/stretchr/testify/assert"
"elyby/minecraft-skinsystem/db"
)
func TestConfig_Face(t *testing.T) {
assert := testify.New(t)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
config, mocks := setupMocks(ctrl)
mocks.Skins.EXPECT().FindByUsername("mock_user").Return(createSkinModel("mock_user", false), nil)
mocks.Log.EXPECT().IncCounter("faces.request", int64(1))
req := httptest.NewRequest("GET", "http://skinsystem.ely.by/skins/mock_user/face.png", nil)
w := httptest.NewRecorder()
config.CreateHandler().ServeHTTP(w, req)
resp := w.Result()
assert.Equal(301, resp.StatusCode)
assert.Equal("http://ely.by/minecraft/skin_buffer/faces/55d2a8848764f5ff04012cdb093458bd.png", resp.Header.Get("Location"))
}
func TestConfig_Face2(t *testing.T) {
assert := testify.New(t)
ctrl := gomock.NewController(t)
defer ctrl.Finish()
config, mocks := setupMocks(ctrl)
mocks.Skins.EXPECT().FindByUsername("mock_user").Return(nil, &db.SkinNotFoundError{"mock_user"})
mocks.Log.EXPECT().IncCounter("faces.request", int64(1))
req := httptest.NewRequest("GET", "http://skinsystem.ely.by/skins/mock_user/face.png", nil)
w := httptest.NewRecorder()
config.CreateHandler().ServeHTTP(w, req)
resp := w.Result()
assert.Equal(301, resp.StatusCode)
assert.Equal("http://ely.by/minecraft/skin_buffer/faces/default.png", resp.Header.Get("Location"))
}

View File

@ -55,8 +55,6 @@ func (cfg *Config) CreateHandler() http.Handler {
router.HandleFunc("/cloaks/{username}", cfg.Cape).Methods("GET").Name("cloaks") router.HandleFunc("/cloaks/{username}", cfg.Cape).Methods("GET").Name("cloaks")
router.HandleFunc("/textures/{username}", cfg.Textures).Methods("GET") router.HandleFunc("/textures/{username}", cfg.Textures).Methods("GET")
router.HandleFunc("/textures/signed/{username}", cfg.SignedTextures).Methods("GET") router.HandleFunc("/textures/signed/{username}", cfg.SignedTextures).Methods("GET")
router.HandleFunc("/skins/{username}/face", cfg.Face).Methods("GET")
router.HandleFunc("/skins/{username}/face.png", cfg.Face).Methods("GET")
// Legacy // Legacy
router.HandleFunc("/skins", cfg.SkinGET).Methods("GET") router.HandleFunc("/skins", cfg.SkinGET).Methods("GET")
router.HandleFunc("/cloaks", cfg.CapeGET).Methods("GET") router.HandleFunc("/cloaks", cfg.CapeGET).Methods("GET")