mirror of
https://github.com/elyby/chrly.git
synced 2024-12-23 13:40:11 +05:30
Resolves #13. Add a config param to completely disable Mojang textures provider
This commit is contained in:
parent
03c5a03c73
commit
092ea3d4e2
@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## [Unreleased] - xxxx-xx-xx
|
||||
### Added
|
||||
- Mojang textures queue now can be completely disabled via `MOJANG_TEXTURES_ENABLED` param.
|
||||
- Remote mode for Mojang's textures queue with a new configuration params: `MOJANG_TEXTURES_UUIDS_PROVIDER_DRIVER` and
|
||||
`MOJANG_TEXTURES_UUIDS_PROVIDER_URL`.
|
||||
|
||||
|
@ -113,6 +113,13 @@ docker-compose up -d app
|
||||
</td>
|
||||
<td><code>10</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>MOJANG_TEXTURES_ENABLED</td>
|
||||
<td>
|
||||
Allows to completely disable Mojang textures provider for unknown usernames. Enabled by default.
|
||||
</td>
|
||||
<td><code>true</code></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>MOJANG_TEXTURES_UUIDS_PROVIDER_DRIVER</td>
|
||||
<td>
|
||||
|
@ -1,6 +1,7 @@
|
||||
package bootstrap
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"os"
|
||||
"time"
|
||||
@ -79,7 +80,7 @@ func CreateMojangUUIDsProvider(emitter http.Emitter) (mojangtextures.UUIDsProvid
|
||||
if preferredUuidsProvider == "remote" {
|
||||
remoteUrl, err := url.Parse(viper.GetString("mojang_textures.uuids_provider.url"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("Unable to parse remote url: %w", err)
|
||||
}
|
||||
|
||||
uuidsProvider = &mojangtextures.RemoteApiUuidsProvider{
|
||||
|
11
cmd/serve.go
11
cmd/serve.go
@ -62,6 +62,8 @@ var serveCmd = &cobra.Command{
|
||||
}
|
||||
logger.Info("Capes repository successfully initialized")
|
||||
|
||||
var mojangTexturesProvider http.MojangTexturesProvider
|
||||
if viper.GetBool("mojang_textures.enabled") {
|
||||
logger.Info("Preparing Mojang's textures queue")
|
||||
mojangUuidsRepository, err := redisFactory.CreateMojangUuidsRepository()
|
||||
if err != nil {
|
||||
@ -71,13 +73,13 @@ var serveCmd = &cobra.Command{
|
||||
|
||||
uuidsProvider, err := bootstrap.CreateMojangUUIDsProvider(dispatcher)
|
||||
if err != nil {
|
||||
logger.Emergency("Unable to parse remote url :err", wd.ErrParam(err))
|
||||
logger.Emergency("Unable to create mojang uuids provider: :err", wd.ErrParam(err))
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
texturesStorage := mojangtextures.NewInMemoryTexturesStorage()
|
||||
texturesStorage.Start()
|
||||
mojangTexturesProvider := &mojangtextures.Provider{
|
||||
mojangTexturesProvider = &mojangtextures.Provider{
|
||||
Emitter: dispatcher,
|
||||
UUIDsProvider: uuidsProvider,
|
||||
TexturesProvider: &mojangtextures.MojangApiTexturesProvider{
|
||||
@ -89,6 +91,10 @@ var serveCmd = &cobra.Command{
|
||||
},
|
||||
}
|
||||
logger.Info("Mojang's textures queue is successfully initialized")
|
||||
} else {
|
||||
logger.Info("Mojang's textures queue is disabled")
|
||||
mojangTexturesProvider = &mojangtextures.NilProvider{}
|
||||
}
|
||||
|
||||
address := fmt.Sprintf("%s:%d", viper.GetString("server.host"), viper.GetInt("server.port"))
|
||||
handler := (&http.Skinsystem{
|
||||
@ -129,4 +135,5 @@ func init() {
|
||||
viper.SetDefault("storage.redis.poll", 10)
|
||||
viper.SetDefault("storage.filesystem.basePath", "data")
|
||||
viper.SetDefault("storage.filesystem.capesDirName", "capes")
|
||||
viper.SetDefault("mojang_textures.enabled", true)
|
||||
}
|
||||
|
12
mojangtextures/nil_mojang_textures.go
Normal file
12
mojangtextures/nil_mojang_textures.go
Normal file
@ -0,0 +1,12 @@
|
||||
package mojangtextures
|
||||
|
||||
import (
|
||||
"github.com/elyby/chrly/api/mojang"
|
||||
)
|
||||
|
||||
type NilProvider struct {
|
||||
}
|
||||
|
||||
func (p *NilProvider) GetForUsername(username string) (*mojang.SignedTexturesResponse, error) {
|
||||
return nil, nil
|
||||
}
|
14
mojangtextures/nil_mojang_textures_test.go
Normal file
14
mojangtextures/nil_mojang_textures_test.go
Normal file
@ -0,0 +1,14 @@
|
||||
package mojangtextures
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNilProvider_GetForUsername(t *testing.T) {
|
||||
provider := &NilProvider{}
|
||||
result, err := provider.GetForUsername("username")
|
||||
assert.Nil(t, result)
|
||||
assert.Nil(t, err)
|
||||
}
|
Loading…
Reference in New Issue
Block a user