2019-11-21 04:03:13 +05:30
|
|
|
package mojangtextures
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/elyby/chrly/api/mojang"
|
|
|
|
)
|
|
|
|
|
2020-04-28 20:27:51 +05:30
|
|
|
// UUIDsStorage is a key-value storage of Mojang usernames pairs to its UUIDs,
|
2019-11-21 04:03:13 +05:30
|
|
|
// used to reduce the load on the account information queue
|
2020-04-28 20:27:51 +05:30
|
|
|
type UUIDsStorage interface {
|
|
|
|
// The second argument indicates whether a record was found in the storage,
|
|
|
|
// since depending on it, the empty value must be interpreted as "no cached record"
|
|
|
|
// or "value cached and has an empty value"
|
|
|
|
GetUuid(username string) (uuid string, found bool, err error)
|
2019-11-21 04:03:13 +05:30
|
|
|
// An empty uuid value can be passed if the corresponding account has not been found
|
|
|
|
StoreUuid(username string, uuid string) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// TexturesStorage is a Mojang's textures storage, used as a values cache to avoid 429 errors
|
|
|
|
type TexturesStorage interface {
|
|
|
|
// Error should not have nil value only if the repository failed to determine if there are any textures
|
|
|
|
// for this uuid or not at all. If there is information about the absence of textures, nil nil should be returned
|
|
|
|
GetTextures(uuid string) (*mojang.SignedTexturesResponse, error)
|
|
|
|
// The nil value can be passed when there are no textures for the corresponding uuid and we know about it
|
|
|
|
StoreTextures(uuid string, textures *mojang.SignedTexturesResponse)
|
|
|
|
}
|
|
|
|
|
|
|
|
type Storage interface {
|
2020-04-28 20:27:51 +05:30
|
|
|
UUIDsStorage
|
2019-11-21 04:03:13 +05:30
|
|
|
TexturesStorage
|
|
|
|
}
|
|
|
|
|
|
|
|
// SeparatedStorage allows you to use separate storage engines to satisfy
|
|
|
|
// the Storage interface
|
|
|
|
type SeparatedStorage struct {
|
2020-04-28 20:27:51 +05:30
|
|
|
UUIDsStorage
|
2019-11-21 04:03:13 +05:30
|
|
|
TexturesStorage
|
|
|
|
}
|
|
|
|
|
2020-04-28 20:27:51 +05:30
|
|
|
func (s *SeparatedStorage) GetUuid(username string) (string, bool, error) {
|
|
|
|
return s.UUIDsStorage.GetUuid(username)
|
2019-11-21 04:03:13 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SeparatedStorage) StoreUuid(username string, uuid string) error {
|
2020-04-28 20:27:51 +05:30
|
|
|
return s.UUIDsStorage.StoreUuid(username, uuid)
|
2019-11-21 04:03:13 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SeparatedStorage) GetTextures(uuid string) (*mojang.SignedTexturesResponse, error) {
|
|
|
|
return s.TexturesStorage.GetTextures(uuid)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SeparatedStorage) StoreTextures(uuid string, textures *mojang.SignedTexturesResponse) {
|
|
|
|
s.TexturesStorage.StoreTextures(uuid, textures)
|
|
|
|
}
|