mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-22 16:41:46 +03:00
[FEATURE] AssetUploadInfo
This commit is contained in:
parent
aff254a875
commit
183cfe949f
11 changed files with 110 additions and 17 deletions
|
@ -43,11 +43,9 @@ public Set<String> getFeatures() {
|
|||
}
|
||||
|
||||
public static void getFeatures(Class<?> clazz, Set<String> 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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
}
|
|
@ -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())));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
}
|
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
|
@ -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<AssetUploadInfoRequestEvent> {
|
||||
@Override
|
||||
public String getType() {
|
||||
return "assetUploadInfo";
|
||||
}
|
||||
}
|
|
@ -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<GetAssetUploadInfoRequestEvent> {
|
||||
public class GetAssetUploadUrl extends Request<GetAssetUploadUrlRequestEvent> {
|
||||
public String name;
|
||||
|
||||
public GetAssetUploadInfo() {
|
||||
public GetAssetUploadUrl() {
|
||||
}
|
||||
|
||||
public GetAssetUploadInfo(String name) {
|
||||
public GetAssetUploadUrl(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue