Handle invalid size params for player skin parts
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0) (push) Successful in 1m5s

This commit is contained in:
Braydon 2024-04-09 00:51:01 -04:00
parent 32c93b5e58
commit ec69120a26
2 changed files with 20 additions and 15 deletions

@ -68,8 +68,7 @@ public final class PlayerController {
@GetMapping("/{query}")
@ResponseBody
public ResponseEntity<CachedPlayer> getPlayer(@PathVariable @NonNull String query)
throws BadRequestException, ResourceNotFoundException, MojangRateLimitException
{
throws BadRequestException, ResourceNotFoundException, MojangRateLimitException {
return ResponseEntity.ofNullable(mojangService.getPlayer(query, false));
}
@ -92,7 +91,7 @@ public final class PlayerController {
@GetMapping("/{partName}/{query}.{extension}")
@ResponseBody
public ResponseEntity<byte[]> getPartTexture(@PathVariable @NonNull String partName, @PathVariable @NonNull String query,
@PathVariable @NonNull String extension, @RequestParam(required = false) Integer size
@PathVariable @NonNull String extension, @RequestParam(required = false) String size
) throws BadRequestException {
return ResponseEntity.ok()
.contentType(extension.equalsIgnoreCase("png") ? MediaType.IMAGE_PNG : MediaType.IMAGE_JPEG)

@ -139,17 +139,24 @@ public final class MojangService {
* Get the part of a skin texture for
* a player by their username or UUID.
*
* @param partName the part of the player's skin texture to get
* @param query the query to search for the player by
* @param extension the skin part image extension
* @param size the size of the skin part image
* @param partName the part of the player's skin texture to get
* @param query the query to search for the player by
* @param extension the skin part image extension
* @param sizeString the size of the skin part image
* @return the skin part texture
* @throws BadRequestException if the extension is invalid
* @throws BadRequestException if the extension is invalid
* @throws MojangRateLimitException if the Mojang API rate limit is reached
*/
public byte[] getSkinPartTexture(@NonNull String partName, @NonNull String query, @NonNull String extension, Integer size)
throws BadRequestException, MojangRateLimitException
{
public byte[] getSkinPartTexture(@NonNull String partName, @NonNull String query, @NonNull String extension, String sizeString)
throws BadRequestException, MojangRateLimitException {
Integer size = null;
if (sizeString != null) { // Attempt to parse the size
try {
size = Integer.parseInt(sizeString);
} catch (NumberFormatException ignored) {
// Safely ignore, invalid number provided
}
}
Skin.Part part = EnumUtils.getEnumConstant(Skin.Part.class, partName.toUpperCase()); // The skin part to get
if (part == null) { // Default to the head part
part = Skin.Part.HEAD;
@ -189,12 +196,11 @@ public final class MojangService {
* @return the player
* @throws BadRequestException if the UUID or username is invalid
* @throws ResourceNotFoundException if the player is not found
* @throws MojangRateLimitException if the Mojang API rate limit is reached
* @throws MojangRateLimitException if the Mojang API rate limit is reached
*/
@NonNull
public CachedPlayer getPlayer(@NonNull String query, boolean bypassCache)
throws BadRequestException, ResourceNotFoundException, MojangRateLimitException
{
throws BadRequestException, ResourceNotFoundException, MojangRateLimitException {
log.info("Requesting player with query: {}", query);
UUID uuid; // The player UUID to lookup
@ -390,7 +396,7 @@ public final class MojangService {
* @param username the player's username
* @return the player's UUID
* @throws ResourceNotFoundException if the player isn't found
* @throws MojangRateLimitException if the Mojang rate limit is reached
* @throws MojangRateLimitException if the Mojang rate limit is reached
*/
@NonNull
private UUID usernameToUUID(@NonNull String username) throws ResourceNotFoundException, MojangRateLimitException {