mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2025-04-29 08:20:30 +05:30
Clean code and throw error if no video was added.
This commit is contained in:
parent
e5556f38e5
commit
48ee0bba85
@ -232,6 +232,8 @@ public class AuthPlaylistHandlers {
|
|||||||
|
|
||||||
var videos = playlist.getVideos();
|
var videos = playlist.getVideos();
|
||||||
|
|
||||||
|
boolean added = false;
|
||||||
|
|
||||||
for (String videoId : videoIds) {
|
for (String videoId : videoIds) {
|
||||||
if (StringUtils.isEmpty(videoId)) continue;
|
if (StringUtils.isEmpty(videoId)) continue;
|
||||||
|
|
||||||
@ -255,19 +257,24 @@ public class AuthPlaylistHandlers {
|
|||||||
|
|
||||||
s.persist(video);
|
s.persist(video);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// only return an error if the unavailable video is the only one in the request
|
ExceptionHandler.handle(e);
|
||||||
if (videoIds.size() == 1) {
|
continue;
|
||||||
return mapper.writeValueAsBytes(mapper.createObjectNode()
|
|
||||||
.put("error", "The video is either private or got deleted"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playlist.getVideos().isEmpty()) playlist.setThumbnail(video.getThumbnail());
|
if (playlist.getVideos().isEmpty()) playlist.setThumbnail(video.getThumbnail());
|
||||||
|
|
||||||
|
added = true;
|
||||||
|
|
||||||
videos.add(video);
|
videos.add(video);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!added) {
|
||||||
|
// only return an error if no videos were added
|
||||||
|
return mapper.writeValueAsBytes(mapper.createObjectNode()
|
||||||
|
.put("error", "Unable to add any videos, since they were unable to be fetched"));
|
||||||
|
}
|
||||||
|
|
||||||
var tr = s.beginTransaction();
|
var tr = s.beginTransaction();
|
||||||
s.merge(playlist);
|
s.merge(playlist);
|
||||||
tr.commit();
|
tr.commit();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user