mirror of
https://github.com/elyby/chrly.git
synced 2024-11-30 10:42:14 +05:30
Возвращаем ошибки по ссылке в реализациях репозиториев
This commit is contained in:
parent
428bedf301
commit
d9629b5e83
@ -15,13 +15,13 @@ type filesDb struct {
|
|||||||
func (repository *filesDb) FindByUsername(username string) (model.Cape, error) {
|
func (repository *filesDb) FindByUsername(username string) (model.Cape, error) {
|
||||||
var record model.Cape
|
var record model.Cape
|
||||||
if username == "" {
|
if username == "" {
|
||||||
return record, CapeNotFoundError{username}
|
return record, &CapeNotFoundError{username}
|
||||||
}
|
}
|
||||||
|
|
||||||
capePath := path.Join(repository.path, strings.ToLower(username) + ".png")
|
capePath := path.Join(repository.path, strings.ToLower(username) + ".png")
|
||||||
file, err := os.Open(capePath)
|
file, err := os.Open(capePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return record, CapeNotFoundError{username}
|
return record, &CapeNotFoundError{username}
|
||||||
}
|
}
|
||||||
|
|
||||||
record.File = file
|
record.File = file
|
||||||
|
@ -19,13 +19,13 @@ const accountIdToUsernameKey string = "hash:username-to-account-id"
|
|||||||
func (db *redisDb) FindByUsername(username string) (model.Skin, error) {
|
func (db *redisDb) FindByUsername(username string) (model.Skin, error) {
|
||||||
var record model.Skin
|
var record model.Skin
|
||||||
if username == "" {
|
if username == "" {
|
||||||
return record, SkinNotFoundError{username}
|
return record, &SkinNotFoundError{username}
|
||||||
}
|
}
|
||||||
|
|
||||||
redisKey := buildKey(username)
|
redisKey := buildKey(username)
|
||||||
response := db.conn.Cmd("GET", redisKey)
|
response := db.conn.Cmd("GET", redisKey)
|
||||||
if response.IsType(redis.Nil) {
|
if response.IsType(redis.Nil) {
|
||||||
return record, SkinNotFoundError{username}
|
return record, &SkinNotFoundError{username}
|
||||||
}
|
}
|
||||||
|
|
||||||
encodedResult, err := response.Bytes()
|
encodedResult, err := response.Bytes()
|
||||||
@ -33,21 +33,19 @@ func (db *redisDb) FindByUsername(username string) (model.Skin, error) {
|
|||||||
result, err := zlibDecode(encodedResult)
|
result, err := zlibDecode(encodedResult)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Cannot uncompress zlib for key " + redisKey)
|
log.Println("Cannot uncompress zlib for key " + redisKey)
|
||||||
goto finish
|
return record, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(result, &record)
|
err = json.Unmarshal(result, &record)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Cannot decode record data for key" + redisKey)
|
log.Println("Cannot decode record data for key" + redisKey)
|
||||||
goto finish
|
return record, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
record.OldUsername = record.Username
|
record.OldUsername = record.Username
|
||||||
}
|
}
|
||||||
|
|
||||||
finish:
|
return record, nil
|
||||||
|
|
||||||
return record, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *redisDb) FindByUserId(id int) (model.Skin, error) {
|
func (db *redisDb) FindByUserId(id int) (model.Skin, error) {
|
||||||
|
@ -61,6 +61,7 @@ func (s *uiService) Textures(response http.ResponseWriter, request *http.Request
|
|||||||
|
|
||||||
cape, err := s.capesRepo.FindByUsername(username)
|
cape, err := s.capesRepo.FindByUsername(username)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
// TODO: восстановить функционал получения ссылки на плащ
|
||||||
// capeUrl, err := services.Router.Get("cloaks").URL("username", username)
|
// capeUrl, err := services.Router.Get("cloaks").URL("username", username)
|
||||||
capeUrl := "/capes/" + username
|
capeUrl := "/capes/" + username
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user