mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Merge pull request #498 from frajibe/master
feat: ability to clear a playlist from its videos (#1952)
This commit is contained in:
commit
8609cf5482
3 changed files with 41 additions and 0 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.clearPlaylistResponse(request.getHeader(AUTHORIZATION), playlistId), "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());
|
||||||
|
|
|
@ -318,6 +318,36 @@ public class AuthPlaylistHandlers {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static byte[] clearPlaylistResponse(String session, String playlistId) throws IOException {
|
||||||
|
|
||||||
|
if (StringUtils.isBlank(session) || StringUtils.isBlank(playlistId))
|
||||||
|
ExceptionHandler.throwErrorResponse(new InvalidRequestResponse("session and playlistId are required parameters"));
|
||||||
|
|
||||||
|
try (Session s = DatabaseSessionFactory.createSession()) {
|
||||||
|
var cb = s.getCriteriaBuilder();
|
||||||
|
var query = cb.createQuery(me.kavin.piped.utils.obj.db.Playlist.class);
|
||||||
|
var root = query.from(me.kavin.piped.utils.obj.db.Playlist.class);
|
||||||
|
query.where(cb.equal(root.get("playlist_id"), UUID.fromString(playlistId)));
|
||||||
|
var playlist = s.createQuery(query).uniqueResult();
|
||||||
|
|
||||||
|
if (playlist == null)
|
||||||
|
return mapper.writeValueAsBytes(mapper.createObjectNode()
|
||||||
|
.put("error", "Playlist not found"));
|
||||||
|
|
||||||
|
if (playlist.getOwner().getId() != DatabaseHelper.getUserFromSession(session).getId())
|
||||||
|
return mapper.writeValueAsBytes(mapper.createObjectNode()
|
||||||
|
.put("error", "You are not the owner this playlist"));
|
||||||
|
|
||||||
|
playlist.setVideos(new ObjectArrayList<>());
|
||||||
|
|
||||||
|
var tr = s.beginTransaction();
|
||||||
|
s.merge(playlist);
|
||||||
|
tr.commit();
|
||||||
|
|
||||||
|
return mapper.writeValueAsBytes(new AcceptedResponse());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static byte[] importPlaylistResponse(String session, String playlistId) throws IOException, ExtractionException {
|
public static byte[] importPlaylistResponse(String session, String playlistId) throws IOException, ExtractionException {
|
||||||
|
|
||||||
if (StringUtils.isBlank(session) || StringUtils.isBlank(playlistId))
|
if (StringUtils.isBlank(session) || StringUtils.isBlank(playlistId))
|
||||||
|
|
|
@ -126,6 +126,9 @@ curl ${CURLOPTS[@]} $HOST/user/playlists/remove -X POST -H "Content-Type: applic
|
||||||
# Rename Playlist Test
|
# Rename Playlist Test
|
||||||
curl ${CURLOPTS[@]} $HOST/user/playlists/delete -X POST -H "Content-Type: application/json" -H "Authorization: $AUTH_TOKEN" -d $(jq -n --compact-output --arg playlistId $PLAYLIST_ID --arg newName $RENAMED_PLAYLIST_NAME '{"playlistId": $playlistId, "newName": $newName}') || exit 1
|
curl ${CURLOPTS[@]} $HOST/user/playlists/delete -X POST -H "Content-Type: application/json" -H "Authorization: $AUTH_TOKEN" -d $(jq -n --compact-output --arg playlistId $PLAYLIST_ID --arg newName $RENAMED_PLAYLIST_NAME '{"playlistId": $playlistId, "newName": $newName}') || exit 1
|
||||||
|
|
||||||
|
# Clear Playlist Test
|
||||||
|
curl ${CURLOPTS[@]} $HOST/user/playlists/clear -X POST -H "Content-Type: application/json" -H "Authorization: $AUTH_TOKEN" -d $(jq -n --compact-output --arg playlistId $PLAYLIST_ID '{"playlistId": $playlistId}') || exit 1
|
||||||
|
|
||||||
# Delete Playlist Test
|
# Delete Playlist Test
|
||||||
curl ${CURLOPTS[@]} $HOST/user/playlists/delete -X POST -H "Content-Type: application/json" -H "Authorization: $AUTH_TOKEN" -d $(jq -n --compact-output --arg playlistId $PLAYLIST_ID '{"playlistId": $playlistId}') || exit 1
|
curl ${CURLOPTS[@]} $HOST/user/playlists/delete -X POST -H "Content-Type: application/json" -H "Authorization: $AUTH_TOKEN" -d $(jq -n --compact-output --arg playlistId $PLAYLIST_ID '{"playlistId": $playlistId}') || exit 1
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue