diff --git a/src/main/java/me/kavin/piped/server/ServerLauncher.java b/src/main/java/me/kavin/piped/server/ServerLauncher.java index bccba11..c571506 100644 --- a/src/main/java/me/kavin/piped/server/ServerLauncher.java +++ b/src/main/java/me/kavin/piped/server/ServerLauncher.java @@ -412,6 +412,14 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher { } catch (Exception e) { return getErrorResponse(e, request.getPath()); } + })).map(POST, "/user/playlists/clear", AsyncServlet.ofBlocking(executor, request -> { + try { + var json = Constants.mapper.readTree(request.loadBody().getResult().asArray()); + var playlistId = json.get("playlistId").textValue(); + return getJsonResponse(AuthPlaylistHandlers.removeFromPlaylistResponse(request.getHeader(AUTHORIZATION), playlistId, null), "private"); + } catch (Exception e) { + return getErrorResponse(e, request.getPath()); + } })).map(POST, "/user/playlists/rename", AsyncServlet.ofBlocking(executor, request -> { try { var json = Constants.mapper.readTree(request.loadBody().getResult().asArray()); diff --git a/src/main/java/me/kavin/piped/server/handlers/auth/AuthPlaylistHandlers.java b/src/main/java/me/kavin/piped/server/handlers/auth/AuthPlaylistHandlers.java index 253598d..3bd8942 100644 --- a/src/main/java/me/kavin/piped/server/handlers/auth/AuthPlaylistHandlers.java +++ b/src/main/java/me/kavin/piped/server/handlers/auth/AuthPlaylistHandlers.java @@ -283,8 +283,7 @@ public class AuthPlaylistHandlers { } } - public static byte[] removeFromPlaylistResponse(String session, String playlistId, int index) throws IOException { - + public static byte[] removeFromPlaylistResponse(String session, String playlistId, Integer index) throws IOException { if (StringUtils.isBlank(session) || StringUtils.isBlank(playlistId)) ExceptionHandler.throwErrorResponse(new InvalidRequestResponse("session and playlistId are required parameters")); @@ -304,11 +303,15 @@ public class AuthPlaylistHandlers { return mapper.writeValueAsBytes(mapper.createObjectNode() .put("error", "You are not the owner this playlist")); - if (index < 0 || index >= playlist.getVideos().size()) - return mapper.writeValueAsBytes(mapper.createObjectNode() - .put("error", "Video Index out of bounds")); + if (index != null) { + if (index < 0 || index >= playlist.getVideos().size()) + return mapper.writeValueAsBytes(mapper.createObjectNode() + .put("error", "Video Index out of bounds")); - playlist.getVideos().remove(index); + playlist.getVideos().remove((int) index); + } else { + playlist.getVideos().clear(); + } var tr = s.beginTransaction(); s.merge(playlist);