Make extra property in the signed textures response to be adjusted

This commit is contained in:
ErickSkrauch 2020-01-06 00:16:38 +03:00
parent 0f2b000d70
commit 57b7c59929
4 changed files with 38 additions and 9 deletions

View File

@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
which is compatible with [Mojang's endpoint](https://wiki.vg/Mojang_API#Username_-.3E_UUID_at_time) to exchange
username to its UUID. It can be used with some load balancing software to increase throughput of Mojang's textures
proxy by splitting the load across multiple servers with its own IPs.
- Textures extra param is now can be configured via `TEXTURES_EXTRA_PARAM_NAME` and `TEXTURES_EXTRA_PARAM_VALUE`.
- New StatsD metrics:
- Counters:

View File

@ -129,6 +129,22 @@ docker-compose up -d app
</td>
<td><code>http://remote-provider.com/api/worker/mojang-uuid</code></td>
</tr>
<tr>
<td>TEXTURES_EXTRA_PARAM_NAME</td>
<td>
Sets the name of the extra property in the
<a href="#get-texturessignedusername">signed textures</a> response.
</td>
<td><code>your-name</code></td>
</tr>
<tr>
<td>TEXTURES_EXTRA_PARAM_VALUE</td>
<td>
Sets the value of the extra property in the
<a href="#get-texturessignedusername">signed textures</a> response.
</td>
<td><code>your awesome joke!</code></td>
</tr>
</tbody>
</table>

View File

@ -81,6 +81,8 @@ var serveCmd = &cobra.Command{
MojangTexturesProvider: mojangTexturesProvider,
Logger: logger,
Auth: &auth.JwtAuth{Key: []byte(viper.GetString("chrly.secret"))},
TexturesExtraParamName: viper.GetString("textures.extra_param_name"),
TexturesExtraParamValue: viper.GetString("textures.extra_param_value"),
}
finishChan := make(chan bool)

View File

@ -88,6 +88,8 @@ type AuthChecker interface {
type Skinsystem struct {
ListenSpec string
TexturesExtraParamName string
TexturesExtraParamValue string
SkinsRepo SkinsRepository
CapesRepo CapesRepository
@ -304,8 +306,8 @@ func (ctx *Skinsystem) SignedTextures(response http.ResponseWriter, request *htt
}
responseData.Props = append(responseData.Props, &mojang.Property{
Name: "chrly",
Value: "how do you tame a horse in Minecraft?",
Name: getStringOrDefault(ctx.TexturesExtraParamName, "chrly"),
Value: getStringOrDefault(ctx.TexturesExtraParamValue, "how do you tame a horse in Minecraft?"),
})
responseJson, _ := json.Marshal(responseData)
@ -496,3 +498,11 @@ func findIdentity(repo SkinsRepository, identityId int, username string) (*model
func parseUsername(username string) string {
return strings.TrimSuffix(username, ".png")
}
func getStringOrDefault(value string, def string) string {
if value != "" {
return value
}
return def
}