diff --git a/build.gradle b/build.gradle index 7708164..f52eb75 100644 --- a/build.gradle +++ b/build.gradle @@ -21,7 +21,6 @@ dependencies { implementation 'com.fasterxml.jackson.core:jackson-core:2.13.4' implementation 'com.fasterxml.jackson.core:jackson-annotations:2.13.4' implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.4.2' - implementation 'org.json:json:20220924' implementation 'com.github.ben-manes.caffeine:caffeine:3.1.1' implementation 'com.rometools:rome:1.18.0' implementation 'com.github.ipfs:java-ipfs-http-client:v1.3.3' diff --git a/src/main/java/me/kavin/piped/server/handlers/SearchHandlers.java b/src/main/java/me/kavin/piped/server/handlers/SearchHandlers.java index 4df9149..075f851 100644 --- a/src/main/java/me/kavin/piped/server/handlers/SearchHandlers.java +++ b/src/main/java/me/kavin/piped/server/handlers/SearchHandlers.java @@ -48,6 +48,9 @@ public class SearchHandlers { public static byte[] searchResponse(String q, String filter) throws IOException, ExtractionException { + if (StringUtils.isEmpty(q) || StringUtils.isEmpty(filter)) + ExceptionHandler.throwErrorResponse(new InvalidRequestResponse("query and filter are required parameters")); + Sentry.setExtra("query", q); final SearchInfo info = SearchInfo.getInfo(YOUTUBE_SERVICE, @@ -65,8 +68,8 @@ public class SearchHandlers { public static byte[] searchPageResponse(String q, String filter, String prevpageStr) throws IOException, ExtractionException { - if (StringUtils.isEmpty(prevpageStr)) - ExceptionHandler.throwErrorResponse(new InvalidRequestResponse("nextpage is a required parameter")); + if (StringUtils.isEmpty(q) || StringUtils.isEmpty(prevpageStr)) + ExceptionHandler.throwErrorResponse(new InvalidRequestResponse("query and nextpage are required parameter")); Page prevpage = mapper.readValue(prevpageStr, Page.class); diff --git a/src/main/java/me/kavin/piped/server/handlers/auth/FeedHandlers.java b/src/main/java/me/kavin/piped/server/handlers/auth/FeedHandlers.java index 2162a4b..23db0be 100644 --- a/src/main/java/me/kavin/piped/server/handlers/auth/FeedHandlers.java +++ b/src/main/java/me/kavin/piped/server/handlers/auth/FeedHandlers.java @@ -119,16 +119,15 @@ public class FeedHandlers { ) .orderBy(cb.desc(root.get("uploaded"))); - List feedItems = new ObjectArrayList<>(); + List feedItems = s.createQuery(criteria).setTimeout(20).stream() + .parallel().map(video -> { + var channel = video.getChannel(); - for (Video video : s.createQuery(criteria).setTimeout(20).list()) { - var channel = video.getChannel(); - - feedItems.add(new StreamItem("/watch?v=" + video.getId(), video.getTitle(), - rewriteURL(video.getThumbnail()), channel.getUploader(), "/channel/" + channel.getUploaderId(), - rewriteURL(channel.getUploaderAvatar()), null, null, video.getDuration(), video.getViews(), - video.getUploaded(), channel.isVerified(), video.isShort())); - } + return new StreamItem("/watch?v=" + video.getId(), video.getTitle(), + rewriteURL(video.getThumbnail()), channel.getUploader(), "/channel/" + channel.getUploaderId(), + rewriteURL(channel.getUploaderAvatar()), null, null, video.getDuration(), video.getViews(), + video.getUploaded(), channel.isVerified(), video.isShort()); + }).toList(); return mapper.writeValueAsBytes(feedItems); } @@ -173,29 +172,27 @@ public class FeedHandlers { ) .orderBy(cb.desc(root.get("uploaded"))); - List