From 183cfe949f70daf023f8e56dbb0c33302be80e70 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Tue, 26 Sep 2023 13:55:01 +0700 Subject: [PATCH] [FEATURE] AssetUploadInfo --- .../launchserver/auth/AuthProviderPair.java | 8 +++--- .../provider/AuthSupportAssetUpload.java | 9 +++++-- .../launchserver/socket/WebSocketService.java | 2 ++ .../cabinet/AssetUploadInfoResponse.java | 27 +++++++++++++++++++ .../cabinet/GetAssetUploadInfoResponse.java | 4 +-- .../launchserver/FeatureCollectionTest.java | 25 +++++++++++++++++ .../request/AssetUploadInfoRequestEvent.java | 24 +++++++++++++++++ ...ava => GetAssetUploadUrlRequestEvent.java} | 6 ++--- .../cabinet/AssetUploadInfoRequest.java | 11 ++++++++ ...UploadInfo.java => GetAssetUploadUrl.java} | 8 +++--- .../websockets/ClientWebSocketService.java | 3 ++- 11 files changed, 110 insertions(+), 17 deletions(-) create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/cabinet/AssetUploadInfoResponse.java create mode 100644 LaunchServer/src/test/java/pro/gravit/launchserver/FeatureCollectionTest.java create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/events/request/AssetUploadInfoRequestEvent.java rename LauncherAPI/src/main/java/pro/gravit/launcher/events/request/{GetAssetUploadInfoRequestEvent.java => GetAssetUploadUrlRequestEvent.java} (64%) create mode 100644 LauncherAPI/src/main/java/pro/gravit/launcher/request/cabinet/AssetUploadInfoRequest.java rename LauncherAPI/src/main/java/pro/gravit/launcher/request/cabinet/{GetAssetUploadInfo.java => GetAssetUploadUrl.java} (50%) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java index 75330311..9645fa01 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java @@ -43,11 +43,9 @@ public Set getFeatures() { } public static void getFeatures(Class clazz, Set list) { - Features features = clazz.getAnnotation(Features.class); - if (features != null) { - for (Feature feature : features.value()) { - list.add(feature.value()); - } + Feature[] features = clazz.getAnnotationsByType(Feature.class); + for (Feature feature : features) { + list.add(feature.value()); } Class superClass = clazz.getSuperclass(); if (superClass != null && superClass != Object.class) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportAssetUpload.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportAssetUpload.java index 617868ff..aaba5b95 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportAssetUpload.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportAssetUpload.java @@ -1,15 +1,20 @@ package pro.gravit.launchserver.auth.core.interfaces.provider; +import pro.gravit.launcher.events.request.AssetUploadInfoRequestEvent; import pro.gravit.launcher.events.request.AuthRequestEvent; -import pro.gravit.launcher.events.request.GetAssetUploadInfoRequestEvent; +import pro.gravit.launcher.events.request.GetAssetUploadUrlRequestEvent; import pro.gravit.launchserver.auth.Feature; import pro.gravit.launchserver.auth.core.User; -@Feature(GetAssetUploadInfoRequestEvent.FEATURE_NAME) +@Feature(GetAssetUploadUrlRequestEvent.FEATURE_NAME) public interface AuthSupportAssetUpload { String getAssetUploadUrl(String name, User user); default AuthRequestEvent.OAuthRequestEvent getAssetUploadToken(String name, User user) { return null; } + + default AssetUploadInfoRequestEvent getAssetUploadInfo(User user) { + return new AssetUploadInfoRequestEvent(true, true, AssetUploadInfoRequestEvent.SlimSupportConf.USER); + } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java index 1dfcd881..03de2060 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java @@ -18,6 +18,7 @@ import pro.gravit.launchserver.socket.response.SimpleResponse; import pro.gravit.launchserver.socket.response.WebSocketServerResponse; import pro.gravit.launchserver.socket.response.auth.*; +import pro.gravit.launchserver.socket.response.cabinet.AssetUploadInfoResponse; import pro.gravit.launchserver.socket.response.cabinet.GetAssetUploadInfoResponse; import pro.gravit.launchserver.socket.response.management.FeaturesResponse; import pro.gravit.launchserver.socket.response.management.GetPublicKeyResponse; @@ -83,6 +84,7 @@ public static void registerResponses() { providers.register("clientProfileKey", FetchClientProfileKeyResponse.class); providers.register("getPublicKey", GetPublicKeyResponse.class); providers.register("getAssetUploadUrl", GetAssetUploadInfoResponse.class); + providers.register("assetUploadInfo", AssetUploadInfoResponse.class); } public static String getIPFromContext(ChannelHandlerContext ctx) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/cabinet/AssetUploadInfoResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/cabinet/AssetUploadInfoResponse.java new file mode 100644 index 00000000..690c9c6e --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/cabinet/AssetUploadInfoResponse.java @@ -0,0 +1,27 @@ +package pro.gravit.launchserver.socket.response.cabinet; + +import io.netty.channel.ChannelHandlerContext; +import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportAssetUpload; +import pro.gravit.launchserver.socket.Client; +import pro.gravit.launchserver.socket.response.SimpleResponse; + +public class AssetUploadInfoResponse extends SimpleResponse { + @Override + public String getType() { + return "assetUploadInfo"; + } + + @Override + public void execute(ChannelHandlerContext ctx, Client client) throws Exception { + if(!client.isAuth || client.auth == null || client.getUser() == null) { + sendError("Access denied"); + return; + } + var support = client.auth.isSupport(AuthSupportAssetUpload.class); + if(support == null) { + sendError("Not supported"); + return; + } + sendResult(support.getAssetUploadInfo(client.getUser())); + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/cabinet/GetAssetUploadInfoResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/cabinet/GetAssetUploadInfoResponse.java index ecac4699..60260f11 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/cabinet/GetAssetUploadInfoResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/cabinet/GetAssetUploadInfoResponse.java @@ -1,7 +1,7 @@ package pro.gravit.launchserver.socket.response.cabinet; import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.events.request.GetAssetUploadInfoRequestEvent; +import pro.gravit.launcher.events.request.GetAssetUploadUrlRequestEvent; import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportAssetUpload; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; @@ -24,6 +24,6 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception { sendError("Not supported"); return; } - sendResult(new GetAssetUploadInfoRequestEvent(support.getAssetUploadUrl(name, client.getUser()), support.getAssetUploadToken(name, client.getUser()))); + sendResult(new GetAssetUploadUrlRequestEvent(support.getAssetUploadUrl(name, client.getUser()), support.getAssetUploadToken(name, client.getUser()))); } } diff --git a/LaunchServer/src/test/java/pro/gravit/launchserver/FeatureCollectionTest.java b/LaunchServer/src/test/java/pro/gravit/launchserver/FeatureCollectionTest.java new file mode 100644 index 00000000..f222f818 --- /dev/null +++ b/LaunchServer/src/test/java/pro/gravit/launchserver/FeatureCollectionTest.java @@ -0,0 +1,25 @@ +package pro.gravit.launchserver; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import pro.gravit.launchserver.auth.AuthProviderPair; +import pro.gravit.launchserver.auth.Feature; + +import java.util.List; + +public class FeatureCollectionTest { + public static class TestClass1 implements TextInterface1 { + + } + + @Feature("test") + public interface TextInterface1 { + + } + + @Test + public void simpleTest() { + var set = AuthProviderPair.getFeatures(TestClass1.class); + Assertions.assertTrue(set.contains("test")); + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/AssetUploadInfoRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/AssetUploadInfoRequestEvent.java new file mode 100644 index 00000000..814f4f37 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/AssetUploadInfoRequestEvent.java @@ -0,0 +1,24 @@ +package pro.gravit.launcher.events.request; + +import pro.gravit.launcher.events.RequestEvent; + +public class AssetUploadInfoRequestEvent extends RequestEvent { + public boolean uploadSkin; + public boolean uploadCape; + public SlimSupportConf slimSupportConf; + + public AssetUploadInfoRequestEvent(boolean uploadSkin, boolean uploadCape, SlimSupportConf slimSupportConf) { + this.uploadSkin = uploadSkin; + this.uploadCape = uploadCape; + this.slimSupportConf = slimSupportConf; + } + + @Override + public String getType() { + return "assetUploadInfo"; + } + + public enum SlimSupportConf { + UNSUPPORTED, USER, SERVER + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAssetUploadInfoRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAssetUploadUrlRequestEvent.java similarity index 64% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAssetUploadInfoRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAssetUploadUrlRequestEvent.java index 789d02eb..9d4a7e66 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAssetUploadInfoRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAssetUploadUrlRequestEvent.java @@ -2,15 +2,15 @@ import pro.gravit.launcher.events.RequestEvent; -public class GetAssetUploadInfoRequestEvent extends RequestEvent { +public class GetAssetUploadUrlRequestEvent extends RequestEvent { public static final String FEATURE_NAME = "assetupload"; public String url; public AuthRequestEvent.OAuthRequestEvent token; - public GetAssetUploadInfoRequestEvent() { + public GetAssetUploadUrlRequestEvent() { } - public GetAssetUploadInfoRequestEvent(String url, AuthRequestEvent.OAuthRequestEvent token) { + public GetAssetUploadUrlRequestEvent(String url, AuthRequestEvent.OAuthRequestEvent token) { this.url = url; this.token = token; } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/cabinet/AssetUploadInfoRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/cabinet/AssetUploadInfoRequest.java new file mode 100644 index 00000000..3827e762 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/cabinet/AssetUploadInfoRequest.java @@ -0,0 +1,11 @@ +package pro.gravit.launcher.request.cabinet; + +import pro.gravit.launcher.events.request.AssetUploadInfoRequestEvent; +import pro.gravit.launcher.request.Request; + +public class AssetUploadInfoRequest extends Request { + @Override + public String getType() { + return "assetUploadInfo"; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/cabinet/GetAssetUploadInfo.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/cabinet/GetAssetUploadUrl.java similarity index 50% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/cabinet/GetAssetUploadInfo.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/request/cabinet/GetAssetUploadUrl.java index 6421c81f..56d9d976 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/cabinet/GetAssetUploadInfo.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/cabinet/GetAssetUploadUrl.java @@ -1,15 +1,15 @@ package pro.gravit.launcher.request.cabinet; -import pro.gravit.launcher.events.request.GetAssetUploadInfoRequestEvent; +import pro.gravit.launcher.events.request.GetAssetUploadUrlRequestEvent; import pro.gravit.launcher.request.Request; -public class GetAssetUploadInfo extends Request { +public class GetAssetUploadUrl extends Request { public String name; - public GetAssetUploadInfo() { + public GetAssetUploadUrl() { } - public GetAssetUploadInfo(String name) { + public GetAssetUploadUrl(String name) { this.name = name; } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java index 927a23b0..c7c269fa 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java @@ -111,7 +111,8 @@ public void registerResults() { results.register("additionalData", AdditionalDataRequestEvent.class); results.register("clientProfileKey", FetchClientProfileKeyRequestEvent.class); results.register("getPublicKey", GetPublicKeyRequestEvent.class); - results.register("getAssetUploadUrl", GetAssetUploadInfoRequestEvent.class); + results.register("getAssetUploadUrl", GetAssetUploadUrlRequestEvent.class); + results.register("assetUploadInfo", AssetUploadInfoRequestEvent.class); resultsRegistered = true; } }