From 1542cff64e6afeb1ff5776efded2d4867ec6b15f Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 6 Apr 2024 18:42:52 +0100 Subject: [PATCH] cache control of 1 hr --- .../cc/fascinated/api/controller/PlayerController.java | 8 ++++++++ src/main/java/cc/fascinated/player/impl/SkinPart.java | 1 + src/main/resources/application.yml | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/cc/fascinated/api/controller/PlayerController.java b/src/main/java/cc/fascinated/api/controller/PlayerController.java index 001a63f..93f54f8 100644 --- a/src/main/java/cc/fascinated/api/controller/PlayerController.java +++ b/src/main/java/cc/fascinated/api/controller/PlayerController.java @@ -5,10 +5,16 @@ import cc.fascinated.player.impl.Player; import cc.fascinated.player.impl.Skin; import cc.fascinated.player.impl.SkinPart; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.CacheControl; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.TimeUnit; + @RestController @RequestMapping(value = "/") public class PlayerController { @@ -35,9 +41,11 @@ public class PlayerController { if (player == null) { return null; } + Skin skin = player.getSkin(); SkinPart head = skin.getHead(); return ResponseEntity.ok() + .cacheControl(CacheControl.maxAge(1, TimeUnit.HOURS).cachePublic()) .contentType(MediaType.IMAGE_PNG) .body(head.getPartData()); } diff --git a/src/main/java/cc/fascinated/player/impl/SkinPart.java b/src/main/java/cc/fascinated/player/impl/SkinPart.java index c6789d7..641ca17 100644 --- a/src/main/java/cc/fascinated/player/impl/SkinPart.java +++ b/src/main/java/cc/fascinated/player/impl/SkinPart.java @@ -71,6 +71,7 @@ public class SkinPart { if (image == null) { return null; } + // Get the part of the image (e.g. the head) BufferedImage partImage = image.getSubimage(this.x, this.y, this.width, this.height); // Scale the image diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 0821e62..e52f767 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -5,7 +5,7 @@ server: whitelabel: enabled: false -public-url: http://localhost +public-url: http://localhost:80 mojang: session-server: https://sessionserver.mojang.com