mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[ANY] Add query helper (#708)
* [ANY] Add query helper * [ANY] Rename AuthCodePassword field to the uri --------- Co-authored-by: d3coder <admin@xakeps.dk>
This commit is contained in:
parent
b719255bd5
commit
1ebe68f5b8
3 changed files with 40 additions and 3 deletions
|
@ -3,10 +3,10 @@
|
|||
import pro.gravit.launcher.base.request.auth.AuthRequest;
|
||||
|
||||
public class AuthCodePassword implements AuthRequest.AuthPasswordInterface {
|
||||
public final String code;
|
||||
public final String uri;
|
||||
|
||||
public AuthCodePassword(String code) {
|
||||
this.code = code;
|
||||
public AuthCodePassword(String uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -258,6 +258,14 @@ public static ArgsParseResult parseJavaArgs(List<String> args) {
|
|||
return new ArgsParseResult(conf, classpath, jvmArgs, mainClass, mainModule, jarFile, args);
|
||||
}
|
||||
|
||||
public static <K, V> V multimapFirstOrNullValue(K key, Map<K, List<V>> params) {
|
||||
List<V> list = params.getOrDefault(key, Collections.emptyList());
|
||||
if (list.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return list.getFirst();
|
||||
}
|
||||
|
||||
public record ArgsParseResult(LaunchOptions.ModuleConf conf, List<String> classpath, List<String> jvmArgs, String mainClass, String mainModule, String jarFile, List<String> args) {
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package pro.gravit.utils.helper;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
public class QueryHelper {
|
||||
public static Map<String, List<String>> splitUriQuery(URI uri) {
|
||||
var query = uri.getRawQuery();
|
||||
if (query == null) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
Map<String, List<String>> params = new HashMap<>();
|
||||
String[] split = query.split("&");
|
||||
for (String qParams : split) {
|
||||
String[] splitParams = qParams.split("=");
|
||||
List<String> strings = params.computeIfAbsent(URLDecoder.decode(splitParams[0], StandardCharsets.UTF_8),
|
||||
k -> new ArrayList<>(1));
|
||||
strings.add(URLDecoder.decode(splitParams[1], StandardCharsets.UTF_8));
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
public static String encodeFormPair(String key, String value) {
|
||||
return URLEncoder.encode(key, StandardCharsets.UTF_8) + "=" + URLEncoder.encode(value, StandardCharsets.UTF_8);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue