This commit is contained in:
@ -6,6 +6,7 @@ import cc.fascinated.model.player.Skin;
|
||||
import cc.fascinated.service.PlayerService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.CacheControl;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -43,6 +44,7 @@ public class PlayerController {
|
||||
return ResponseEntity.ok()
|
||||
.cacheControl(cacheControl)
|
||||
.contentType(MediaType.IMAGE_PNG)
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=%s.png".formatted(player.getUsername()))
|
||||
.body(PlayerUtils.getSkinPartBytes(player.getSkin(), skinPart, size));
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,14 @@
|
||||
package cc.fascinated.controller;
|
||||
|
||||
import cc.fascinated.common.ServerUtils;
|
||||
import cc.fascinated.common.Tuple;
|
||||
import cc.fascinated.model.cache.CachedMinecraftServer;
|
||||
import cc.fascinated.model.server.JavaMinecraftServer;
|
||||
import cc.fascinated.model.server.MinecraftServer;
|
||||
import cc.fascinated.service.ServerService;
|
||||
import cc.fascinated.service.pinger.impl.JavaMinecraftServerPinger;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@ -19,14 +23,19 @@ public class ServerController {
|
||||
@ResponseBody
|
||||
@GetMapping(value = "/{platform}/{hostnameAndPort}", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public CachedMinecraftServer getServer(@PathVariable String platform, @PathVariable String hostnameAndPort) {
|
||||
String[] split = hostnameAndPort.split(":");
|
||||
String hostname = split[0];
|
||||
int port = 25565;
|
||||
if (split.length == 2) {
|
||||
try {
|
||||
port = Integer.parseInt(split[1]);
|
||||
} catch (NumberFormatException ignored) {}
|
||||
}
|
||||
return serverService.getServer(platform, hostname, port);
|
||||
Tuple<String, Integer> host = ServerUtils.getHostnameAndPort(hostnameAndPort);
|
||||
return serverService.getServer(platform, host.getLeft(), host.getRight());
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@GetMapping(value = "/icon/{hostnameAndPort}", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<?> getServerIcon(@PathVariable String hostnameAndPort) {
|
||||
Tuple<String, Integer> host = ServerUtils.getHostnameAndPort(hostnameAndPort);
|
||||
String hostname = host.getLeft();
|
||||
int port = host.getRight();
|
||||
return ResponseEntity.ok()
|
||||
.contentType(MediaType.IMAGE_PNG)
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=%s.png".formatted(ServerUtils.getAddress(hostname, port)))
|
||||
.body(serverService.getServerFavicon(hostname, port));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user