Update the return json of /mojang/status in the API
All checks were successful
Deploy API / docker (17, 3.8.5) (push) Successful in 2m14s

This commit is contained in:
Braydon 2024-04-18 13:09:23 -04:00
parent 979018b508
commit fd16430307
2 changed files with 22 additions and 9 deletions

@ -39,14 +39,19 @@ import java.net.UnknownHostException;
*/ */
@AllArgsConstructor @Getter @ToString @AllArgsConstructor @Getter @ToString
public enum MojangServer { public enum MojangServer {
SESSION("https://sessionserver.mojang.com"), SESSION("Session Server", "https://sessionserver.mojang.com"),
API("https://api.mojang.com"), API("Mojang API", "https://api.mojang.com"),
TEXTURES("https://textures.minecraft.net"), TEXTURES("Textures Server", "https://textures.minecraft.net"),
ASSETS("https://assets.mojang.com"), ASSETS("Assets Server", "https://assets.mojang.com"),
LIBRARIES("https://libraries.minecraft.net"); LIBRARIES("Libraries Server", "https://libraries.minecraft.net");
private static final int STATUS_TIMEOUT = 7000; private static final int STATUS_TIMEOUT = 7000;
/**
* The name of this server.
*/
@NonNull private final String name;
/** /**
* The endpoint of this service. * The endpoint of this service.
*/ */

@ -37,7 +37,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -68,11 +70,17 @@ public final class MojangController {
*/ */
@GetMapping("/status") @GetMapping("/status")
@ResponseBody @ResponseBody
public ResponseEntity<Map<String, String>> getStatus() throws BadRequestException { public ResponseEntity<Map<String, List<Map<String, Object>>>> getStatus() throws BadRequestException {
Map<String, String> response = new HashMap<>(); List<Map<String, Object>> servers = new ArrayList<>();
for (Map.Entry<MojangServer, MojangServer.Status> entry : mojangService.getMojangServerStatuses().entrySet()) { for (Map.Entry<MojangServer, MojangServer.Status> entry : mojangService.getMojangServerStatuses().entrySet()) {
response.put(entry.getKey().getEndpoint(), entry.getValue().name()); MojangServer server = entry.getKey();
Map<String, Object> serverStatus = new HashMap<>();
serverStatus.put("name", server.getName());
serverStatus.put("endpoint", server.getEndpoint());
serverStatus.put("status", entry.getValue().name());
servers.add(serverStatus);
} }
return ResponseEntity.ok(response); return ResponseEntity.ok(Map.of("servers", servers));
} }
} }