mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
add post parameter for duplicates
This commit is contained in:
parent
c76d1e0282
commit
0625b59e64
2 changed files with 12 additions and 6 deletions
|
@ -332,7 +332,9 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher {
|
|||
var json = Constants.mapper.readTree(request.loadBody().getResult().asArray());
|
||||
var playlistId = json.get("playlistId").textValue();
|
||||
var videoId = json.get("videoId").textValue();
|
||||
return getJsonResponse(ResponseHelper.addToPlaylistResponse(request.getHeader(AUTHORIZATION), playlistId, videoId), "private");
|
||||
var allowDupicatesValue = json.get("allowDuplicates");
|
||||
var allowDuplicates = allowDupicatesValue == null ? true : allowDupicatesValue.booleanValue();
|
||||
return getJsonResponse(ResponseHelper.addToPlaylistResponse(request.getHeader(AUTHORIZATION), playlistId, videoId, allowDuplicates), "private");
|
||||
} catch (Exception e) {
|
||||
return getErrorResponse(e, request.getPath());
|
||||
}
|
||||
|
|
|
@ -1390,7 +1390,7 @@ public class ResponseHelper {
|
|||
);
|
||||
}
|
||||
|
||||
public static byte[] addToPlaylistResponse(String session, String playlistId, String videoId) throws IOException, ExtractionException {
|
||||
public static byte[] addToPlaylistResponse(String session, String playlistId, String videoId, Boolean allowDuplicates) throws IOException, ExtractionException {
|
||||
|
||||
if (StringUtils.isBlank(playlistId) || StringUtils.isBlank(videoId))
|
||||
return mapper.writeValueAsBytes(new InvalidRequestResponse());
|
||||
|
@ -1413,10 +1413,14 @@ public class ResponseHelper {
|
|||
return mapper.writeValueAsBytes(mapper.createObjectNode()
|
||||
.put("error", "Playlist not found"));
|
||||
|
||||
if (!allowDuplicates) {
|
||||
for (PlaylistVideo video : playlist.getVideos()) {
|
||||
if (video.getId() == videoId) return mapper.writeValueAsBytes(mapper.createObjectNode()
|
||||
.put("error", "Playlist already contains the video"));
|
||||
};
|
||||
if (video.getId() == videoId)
|
||||
return mapper.writeValueAsBytes(mapper.createObjectNode()
|
||||
.put("error", "The playlist already contains the video"));
|
||||
}
|
||||
;
|
||||
}
|
||||
|
||||
if (playlist.getOwner().getId() != user.getId())
|
||||
return mapper.writeValueAsBytes(mapper.createObjectNode()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue