fix server example and add an endpoint to get uuid from username

This commit is contained in:
Lee 2024-04-11 00:21:36 +01:00
parent 624dcc0be6
commit a3b9cb5e77
4 changed files with 18 additions and 6 deletions

@ -13,13 +13,13 @@ public class HomeController {
* The example UUID. * The example UUID.
*/ */
private final String exampleUuid = "eeab5f8a-18dd-4d58-af78-2b3c4543da48"; private final String exampleUuid = "eeab5f8a-18dd-4d58-af78-2b3c4543da48";
private final String exampleServer = "eeab5f8a-18dd-4d58-af78-2b3c4543da48"; private final String exampleServer = "aetheria.cc";
@RequestMapping(value = "/") @RequestMapping(value = "/")
public String home(Model model) { public String home(Model model) {
model.addAttribute("player_example_url", Config.INSTANCE.getWebPublicUrl() + "/player/" + exampleUuid); model.addAttribute("player_example_url", Config.INSTANCE.getWebPublicUrl() + "/player/" + exampleUuid);
model.addAttribute("java_server_example_url", Config.INSTANCE.getWebPublicUrl() + "/server/java/" + exampleServer); model.addAttribute("java_server_example_url", Config.INSTANCE.getWebPublicUrl() + "/server/java/" + exampleServer);
model.addAttribute("swagger_url", Config.INSTANCE.getWebPublicUrl() + "/docs"); model.addAttribute("swagger_url", Config.INSTANCE.getWebPublicUrl() + "/swagger-ui.html");
return "index"; return "index";
} }
} }

@ -12,6 +12,7 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@RestController @RestController
@ -36,6 +37,17 @@ public class PlayerController {
.body(playerService.getPlayer(id)); .body(playerService.getPlayer(id));
} }
@ResponseBody
@GetMapping(value = "/uuid/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getPlayerUuid(
@Parameter(description = "The UUID or Username of the player", example = "ImFascinated") @PathVariable String id) {
CachedPlayer player = playerService.getPlayer(id);
return ResponseEntity.ok(Map.of(
"username", player.getUsername(),
"uuid", player.getUuid().toString()
));
}
@GetMapping(value = "/{part}/{id}") @GetMapping(value = "/{part}/{id}")
public ResponseEntity<?> getPlayerHead( public ResponseEntity<?> getPlayerHead(
@Parameter(description = "The part of the skin", example = "head") @PathVariable String part, @Parameter(description = "The part of the skin", example = "head") @PathVariable String part,

@ -31,14 +31,14 @@ public class ServerController {
@GetMapping(value = "/{platform}/{hostname}", produces = MediaType.APPLICATION_JSON_VALUE) @GetMapping(value = "/{platform}/{hostname}", produces = MediaType.APPLICATION_JSON_VALUE)
public CachedMinecraftServer getServer( public CachedMinecraftServer getServer(
@Parameter(description = "The platform of the server", example = "java") @PathVariable String platform, @Parameter(description = "The platform of the server", example = "java") @PathVariable String platform,
@Parameter(description = "The hostname and port of the server", example = "play.hypixel.net") @PathVariable String hostname) { @Parameter(description = "The hostname and port of the server", example = "aetheria.cc") @PathVariable String hostname) {
return serverService.getServer(platform, hostname); return serverService.getServer(platform, hostname);
} }
@ResponseBody @ResponseBody
@GetMapping(value = "/icon/{hostname}", produces = MediaType.IMAGE_PNG_VALUE) @GetMapping(value = "/icon/{hostname}", produces = MediaType.IMAGE_PNG_VALUE)
public ResponseEntity<?> getServerIcon( public ResponseEntity<?> getServerIcon(
@Parameter(description = "The hostname and port of the server", example = "play.hypixel.net") @PathVariable String hostname, @Parameter(description = "The hostname and port of the server", example = "aetheria.cc") @PathVariable String hostname,
@Parameter(description = "Whether to download the image") @RequestParam(required = false, defaultValue = "false") boolean download) { @Parameter(description = "Whether to download the image") @RequestParam(required = false, defaultValue = "false") boolean download) {
String dispositionHeader = download ? "attachment; filename=%s.png" : "inline; filename=%s.png"; String dispositionHeader = download ? "attachment; filename=%s.png" : "inline; filename=%s.png";
@ -51,7 +51,7 @@ public class ServerController {
@ResponseBody @ResponseBody
@GetMapping(value = "/blocked/{hostname}", produces = MediaType.APPLICATION_JSON_VALUE) @GetMapping(value = "/blocked/{hostname}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> getServerBlockedStatus( public ResponseEntity<?> getServerBlockedStatus(
@Parameter(description = "The hostname of the server", example = "play.hypixel.net") @PathVariable String hostname) { @Parameter(description = "The hostname of the server", example = "aetheria.cc") @PathVariable String hostname) {
return ResponseEntity.ok(Map.of( return ResponseEntity.ok(Map.of(
"blocked", mojangService.isServerBlocked(hostname) "blocked", mojangService.isServerBlocked(hostname)
)); ));

@ -91,7 +91,7 @@ public class PlayerService {
* @param username the username of the player * @param username the username of the player
* @return the uuid of the player * @return the uuid of the player
*/ */
private UUID usernameToUuid(String username) { public UUID usernameToUuid(String username) {
log.info("Getting UUID from username: {}", username); log.info("Getting UUID from username: {}", username);
Optional<CachedPlayerName> cachedPlayerName = playerNameCacheRepository.findById(username.toUpperCase()); Optional<CachedPlayerName> cachedPlayerName = playerNameCacheRepository.findById(username.toUpperCase());
if (cachedPlayerName.isPresent()) { if (cachedPlayerName.isPresent()) {