From cef4b1dcb7c95e4e762ec542f0ca743dcdc0a136 Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Thu, 7 Apr 2022 18:40:34 +0100 Subject: [PATCH] Handle JSON data better. --- src/main/java/me/kavin/piped/ServerLauncher.java | 12 ++++++------ .../piped/utils/resp/InvalidRequestResponse.java | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/me/kavin/piped/ServerLauncher.java b/src/main/java/me/kavin/piped/ServerLauncher.java index 45f6ea4..21732ec 100644 --- a/src/main/java/me/kavin/piped/ServerLauncher.java +++ b/src/main/java/me/kavin/piped/ServerLauncher.java @@ -283,7 +283,7 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher { } })).map(POST, "/user/playlists/create", AsyncServlet.ofBlocking(executor, request -> { try { - var name = Constants.mapper.readTree(request.loadBody().getResult().asArray()).get("name").asText(); + var name = Constants.mapper.readTree(request.loadBody().getResult().asArray()).get("name").textValue(); return getJsonResponse(ResponseHelper.createPlaylist(request.getHeader(AUTHORIZATION), name), "private"); } catch (Exception e) { return getErrorResponse(e, request.getPath()); @@ -297,8 +297,8 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher { })).map(POST, "/user/playlists/add", AsyncServlet.ofBlocking(executor, request -> { try { var json = Constants.mapper.readTree(request.loadBody().getResult().asArray()); - var playlistId = json.get("playlistId").asText(); - var videoId = json.get("videoId").asText(); + var playlistId = json.get("playlistId").textValue(); + var videoId = json.get("videoId").textValue(); return getJsonResponse(ResponseHelper.addToPlaylistResponse(request.getHeader(AUTHORIZATION), playlistId, videoId), "private"); } catch (Exception e) { return getErrorResponse(e, request.getPath()); @@ -306,8 +306,8 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher { })).map(POST, "/user/playlists/remove", AsyncServlet.ofBlocking(executor, request -> { try { var json = Constants.mapper.readTree(request.loadBody().getResult().asArray()); - var playlistId = json.get("playlistId").asText(); - var index = json.get("index").asInt(); + var playlistId = json.get("playlistId").textValue(); + var index = json.get("index").intValue(); return getJsonResponse(ResponseHelper.removeFromPlaylistResponse(request.getHeader(AUTHORIZATION), playlistId, index), "private"); } catch (Exception e) { return getErrorResponse(e, request.getPath()); @@ -315,7 +315,7 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher { })).map(POST, "/user/playlists/delete", AsyncServlet.ofBlocking(executor, request -> { try { var json = Constants.mapper.readTree(request.loadBody().getResult().asArray()); - var playlistId = json.get("playlistId").asText(); + var playlistId = json.get("playlistId").textValue(); return getJsonResponse(ResponseHelper.deletePlaylistResponse(request.getHeader(AUTHORIZATION), playlistId), "private"); } catch (Exception e) { return getErrorResponse(e, request.getPath()); diff --git a/src/main/java/me/kavin/piped/utils/resp/InvalidRequestResponse.java b/src/main/java/me/kavin/piped/utils/resp/InvalidRequestResponse.java index e64852f..0a6ab77 100644 --- a/src/main/java/me/kavin/piped/utils/resp/InvalidRequestResponse.java +++ b/src/main/java/me/kavin/piped/utils/resp/InvalidRequestResponse.java @@ -2,6 +2,6 @@ package me.kavin.piped.utils.resp; public class InvalidRequestResponse { - public String message = "Invalid request sent."; + public String error = "Invalid request sent."; }