diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4c6ced5..237bfac 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,7 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- [#24](https://github.com/elyby/chrly/issues/24): Implemented a new strategy for the queue in the batch provider of
Mojang UUIDs: `full-bus`.
-- A new configuration param `QUEUE_STRATEGY` with the default value `periodic`.
+- New configuration param `QUEUE_STRATEGY` with the default value `periodic`.
+- New configuration params: `MOJANG_API_BASE_URL` and `MOJANG_SESSION_SERVER_BASE_URL`, that allow you to spoof
+ Mojang API base addresses.
### Changed
- `ely.skinsystem.{hostname}.app.mojang_textures.usernames.round_time` timer will not be recorded if the iteration was
diff --git a/README.md b/README.md
index 95e7dcc..39db1d9 100644
--- a/README.md
+++ b/README.md
@@ -145,6 +145,20 @@ docker-compose up -d app
TEXTURES_EXTRA_PARAM_NAME |
diff --git a/api/mojang/mojang.go b/api/mojang/mojang.go
index 7527b97..a50a015 100644
--- a/api/mojang/mojang.go
+++ b/api/mojang/mojang.go
@@ -58,11 +58,17 @@ type ProfileInfo struct {
IsDemo bool `json:"demo,omitempty"`
}
+var ApiMojangDotComAddr = "https://api.mojang.com"
+var SessionServerMojangComAddr = "https://sessionserver.mojang.com"
+
// Exchanges usernames array to array of uuids
// See https://wiki.vg/Mojang_API#Playernames_-.3E_UUIDs
func UsernamesToUuids(usernames []string) ([]*ProfileInfo, error) {
requestBody, _ := json.Marshal(usernames)
- request, _ := http.NewRequest("POST", "https://api.mojang.com/profiles/minecraft", bytes.NewBuffer(requestBody))
+ request, err := http.NewRequest("POST", ApiMojangDotComAddr+"/profiles/minecraft", bytes.NewBuffer(requestBody))
+ if err != nil {
+ return nil, err
+ }
request.Header.Set("Content-Type", "application/json")
@@ -88,12 +94,15 @@ func UsernamesToUuids(usernames []string) ([]*ProfileInfo, error) {
// See https://wiki.vg/Mojang_API#UUID_-.3E_Profile_.2B_Skin.2FCape
func UuidToTextures(uuid string, signed bool) (*SignedTexturesResponse, error) {
normalizedUuid := strings.ReplaceAll(uuid, "-", "")
- url := "https://sessionserver.mojang.com/session/minecraft/profile/" + normalizedUuid
+ url := SessionServerMojangComAddr + "/session/minecraft/profile/" + normalizedUuid
if signed {
url += "?unsigned=false"
}
- request, _ := http.NewRequest("GET", url, nil)
+ request, err := http.NewRequest("GET", url, nil)
+ if err != nil {
+ return nil, err
+ }
response, err := HttpClient.Do(request)
if err != nil {
diff --git a/di/mojang_textures.go b/di/mojang_textures.go
index 42f385c..10cfdea 100644
--- a/di/mojang_textures.go
+++ b/di/mojang_textures.go
@@ -9,12 +9,14 @@ import (
"github.com/goava/di"
"github.com/spf13/viper"
+ "github.com/elyby/chrly/api/mojang"
es "github.com/elyby/chrly/eventsubscribers"
"github.com/elyby/chrly/http"
"github.com/elyby/chrly/mojangtextures"
)
var mojangTextures = di.Options(
+ di.Invoke(interceptMojangApiUrls),
di.Provide(newMojangTexturesProviderFactory),
di.Provide(newMojangTexturesProvider),
di.Provide(newMojangTexturesUuidsProviderFactory),
@@ -27,6 +29,30 @@ var mojangTextures = di.Options(
di.Provide(newMojangTexturesStorageFactory),
)
+func interceptMojangApiUrls(config *viper.Viper) error {
+ apiUrl := config.GetString("mojang.api_base_url")
+ if apiUrl != "" {
+ u, err := url.ParseRequestURI(apiUrl)
+ if err != nil {
+ return err
+ }
+
+ mojang.ApiMojangDotComAddr = u.String()
+ }
+
+ sessionServerUrl := config.GetString("mojang.session_server_base_url")
+ if sessionServerUrl != "" {
+ u, err := url.ParseRequestURI(apiUrl)
+ if err != nil {
+ return err
+ }
+
+ mojang.SessionServerMojangComAddr = u.String()
+ }
+
+ return nil
+}
+
func newMojangTexturesProviderFactory(
container *di.Container,
config *viper.Viper,
|