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 json = Constants.mapper.readTree(request.loadBody().getResult().asArray());
|
||||||
var playlistId = json.get("playlistId").textValue();
|
var playlistId = json.get("playlistId").textValue();
|
||||||
var videoId = json.get("videoId").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) {
|
} catch (Exception e) {
|
||||||
return getErrorResponse(e, request.getPath());
|
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))
|
if (StringUtils.isBlank(playlistId) || StringUtils.isBlank(videoId))
|
||||||
return mapper.writeValueAsBytes(new InvalidRequestResponse());
|
return mapper.writeValueAsBytes(new InvalidRequestResponse());
|
||||||
|
@ -1413,10 +1413,14 @@ public class ResponseHelper {
|
||||||
return mapper.writeValueAsBytes(mapper.createObjectNode()
|
return mapper.writeValueAsBytes(mapper.createObjectNode()
|
||||||
.put("error", "Playlist not found"));
|
.put("error", "Playlist not found"));
|
||||||
|
|
||||||
for (PlaylistVideo video : playlist.getVideos()) {
|
if (!allowDuplicates) {
|
||||||
if (video.getId() == videoId) return mapper.writeValueAsBytes(mapper.createObjectNode()
|
for (PlaylistVideo video : playlist.getVideos()) {
|
||||||
.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())
|
if (playlist.getOwner().getId() != user.getId())
|
||||||
return mapper.writeValueAsBytes(mapper.createObjectNode()
|
return mapper.writeValueAsBytes(mapper.createObjectNode()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue