[FIX] Improve JsonTextureProvider

This commit is contained in:
Gravita 2023-10-22 18:07:50 +07:00
parent d262b99be6
commit 2e6d7bd94a
2 changed files with 12 additions and 2 deletions

View file

@ -21,6 +21,10 @@ public <T> SimpleErrorHandler<T> makeEH(Class<T> clazz) {
return new SimpleErrorHandler<>(clazz);
}
public <T> SimpleErrorHandler<T> makeEH(Type clazz) {
return new SimpleErrorHandler<>(clazz);
}
public <T> HttpRequest get(String url, String token) {
try {
var requestBuilder = HttpRequest.newBuilder()
@ -59,6 +63,10 @@ public <T> HttpHelper.HttpOptional<T, SimpleError> send(HttpRequest request, Cla
return HttpHelper.send(httpClient, request, makeEH(clazz));
}
public <T> HttpHelper.HttpOptional<T, SimpleError> send(HttpRequest request, Type type) throws IOException {
return HttpHelper.send(httpClient, request, makeEH(type));
}
public static class SimpleErrorHandler<T> implements HttpHelper.HttpJsonErrorHandler<T, SimpleError> {
private final Type type;

View file

@ -6,6 +6,7 @@
import pro.gravit.launcher.HTTPRequest;
import pro.gravit.launcher.Launcher;
import pro.gravit.launcher.profiles.Texture;
import pro.gravit.launchserver.HttpRequester;
import pro.gravit.utils.helper.SecurityHelper;
import java.io.IOException;
@ -19,7 +20,9 @@ public class JsonTextureProvider extends TextureProvider {
private static final Type MAP_TYPE = new TypeToken<Map<String, JsonTexture>>() {
}.getType();
private transient final Logger logger = LogManager.getLogger();
private transient final HttpRequester requester = new HttpRequester();
public String url;
public String bearerToken;
@Override
public void close() {
@ -41,8 +44,7 @@ public Texture getSkinTexture(UUID uuid, String username, String client) {
@Override
public Map<String, Texture> getAssets(UUID uuid, String username, String client) {
try {
var result = HTTPRequest.jsonRequest(null, "GET", new URL(RequestTextureProvider.getTextureURL(url, uuid, username, client)));
Map<String, JsonTexture> map = Launcher.gsonManager.gson.fromJson(result, MAP_TYPE);
Map<String, JsonTexture> map = requester.<Map<String, JsonTexture>>send(requester.get(RequestTextureProvider.getTextureURL(url, uuid, username, client), bearerToken), MAP_TYPE).getOrThrow();
return JsonTexture.convertMap(map);
} catch (IOException e) {
logger.error("JsonTextureProvider", e);