mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
feat: ability to clear a playlist from its videos (#1952)
This commit is contained in:
parent
09d538d355
commit
fef6022104
2 changed files with 17 additions and 6 deletions
|
@ -412,6 +412,14 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return getErrorResponse(e, request.getPath());
|
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 -> {
|
})).map(POST, "/user/playlists/rename", AsyncServlet.ofBlocking(executor, request -> {
|
||||||
try {
|
try {
|
||||||
var json = Constants.mapper.readTree(request.loadBody().getResult().asArray());
|
var json = Constants.mapper.readTree(request.loadBody().getResult().asArray());
|
||||||
|
|
|
@ -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))
|
if (StringUtils.isBlank(session) || StringUtils.isBlank(playlistId))
|
||||||
ExceptionHandler.throwErrorResponse(new InvalidRequestResponse("session and playlistId are required parameters"));
|
ExceptionHandler.throwErrorResponse(new InvalidRequestResponse("session and playlistId are required parameters"));
|
||||||
|
|
||||||
|
@ -304,11 +303,15 @@ public class AuthPlaylistHandlers {
|
||||||
return mapper.writeValueAsBytes(mapper.createObjectNode()
|
return mapper.writeValueAsBytes(mapper.createObjectNode()
|
||||||
.put("error", "You are not the owner this playlist"));
|
.put("error", "You are not the owner this playlist"));
|
||||||
|
|
||||||
if (index < 0 || index >= playlist.getVideos().size())
|
if (index != null) {
|
||||||
return mapper.writeValueAsBytes(mapper.createObjectNode()
|
if (index < 0 || index >= playlist.getVideos().size())
|
||||||
.put("error", "Video Index out of bounds"));
|
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();
|
var tr = s.beginTransaction();
|
||||||
s.merge(playlist);
|
s.merge(playlist);
|
||||||
|
|
Loading…
Reference in a new issue