mirror of
https://github.com/ReaJason/MemShellParty.git
synced 2026-09-21 22:50:42 +08:00
refactor: deserialize
This commit is contained in:
@@ -24,6 +24,7 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation project(":deserialize")
|
||||
implementation project(":generator")
|
||||
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.reajason.javaweb.boot.controller;
|
||||
|
||||
import com.reajason.javaweb.boot.entity.Config;
|
||||
import com.reajason.javaweb.config.Server;
|
||||
import com.reajason.javaweb.config.ShellTool;
|
||||
import com.reajason.javaweb.deserialize.PayloadType;
|
||||
import com.reajason.javaweb.memsell.AbstractShell;
|
||||
import com.reajason.javaweb.memsell.packer.Packer;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2024/12/13
|
||||
*/
|
||||
@RestController("/config")
|
||||
public class ConfigController {
|
||||
@RequestMapping
|
||||
public ResponseEntity<?> config() {
|
||||
Map<String, Map<?, ?>> coreMap = new HashMap<>(16);
|
||||
List<String> servers = new ArrayList<>();
|
||||
for (Server value : Server.values()) {
|
||||
AbstractShell shell = value.getShell();
|
||||
if (shell != null) {
|
||||
List<ShellTool> supportedShellTools = shell.getSupportedShellTools();
|
||||
Map<String, List<String>> map = new HashMap<>(16);
|
||||
for (ShellTool shellTool : supportedShellTools) {
|
||||
List<String> supportedShellTypes = shell.getSupportedShellTypes(shellTool);
|
||||
map.put(shellTool.name(), supportedShellTypes);
|
||||
}
|
||||
servers.add(value.name());
|
||||
coreMap.put(value.name(), map);
|
||||
}
|
||||
}
|
||||
Config config = new Config();
|
||||
config.setServers(servers);
|
||||
config.setCore(coreMap);
|
||||
Map<String, Map<?, ?>> packerMap = new HashMap<>(16);
|
||||
for (Packer.INSTANCE value : Packer.INSTANCE.values()) {
|
||||
if (value.equals(Packer.INSTANCE.Deserialize)) {
|
||||
packerMap.put(value.name(), Map.of("payloads", PayloadType.values()));
|
||||
} else {
|
||||
packerMap.put(value.name(), null);
|
||||
}
|
||||
}
|
||||
config.setPacker(packerMap);
|
||||
return ResponseEntity.ok(config);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.reajason.javaweb.boot.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2024/12/13
|
||||
*/
|
||||
@Data
|
||||
public class Config {
|
||||
private List<String> servers;
|
||||
private Map<String, Map<?, ?>> core;
|
||||
private Map<String, Map<?, ?>> packer;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.reajason.javaweb.boot.controller;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/**
|
||||
* @author ReaJason
|
||||
* @since 2024/12/13
|
||||
*/
|
||||
class ConfigControllerTest {
|
||||
@Test
|
||||
void getConfig() {
|
||||
ConfigController configController = new ConfigController();
|
||||
ResponseEntity<?> config = configController.config();
|
||||
Object body = config.getBody();
|
||||
assertNotNull(body);
|
||||
System.out.println(body);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user