Add some parameter checking to search and feed routes. (#294)

This commit is contained in:
Kavin 2022-06-28 18:13:29 +01:00 committed by GitHub
parent 374d067a95
commit 943e4a3de8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 1 deletions

View File

@ -491,6 +491,9 @@ public class ResponseHelper {
public static byte[] suggestionsResponse(String query)
throws IOException, ExtractionException {
if (StringUtils.isEmpty(query))
return mapper.writeValueAsBytes(new InvalidRequestResponse());
return mapper.writeValueAsBytes(YOUTUBE_SERVICE.getSuggestionExtractor().suggestionList(query));
}
@ -498,6 +501,9 @@ public class ResponseHelper {
public static byte[] opensearchSuggestionsResponse(String query)
throws IOException, ExtractionException {
if (StringUtils.isEmpty(query))
return mapper.writeValueAsBytes(new InvalidRequestResponse());
return mapper.writeValueAsBytes(Arrays.asList(
query,
YOUTUBE_SERVICE.getSuggestionExtractor().suggestionList(query)
@ -836,6 +842,9 @@ public class ResponseHelper {
public static byte[] feedResponse(String session) throws IOException {
if (StringUtils.isBlank(session))
return mapper.writeValueAsBytes(new AuthenticationFailureResponse());
User user = DatabaseHelper.getUserFromSession(session);
if (user != null) {
@ -876,6 +885,9 @@ public class ResponseHelper {
public static byte[] feedResponseRSS(String session) throws IOException, FeedException {
if (StringUtils.isBlank(session))
return mapper.writeValueAsBytes(new AuthenticationFailureResponse());
User user = DatabaseHelper.getUserFromSession(session);
if (user != null) {
@ -1062,7 +1074,7 @@ public class ResponseHelper {
s.remove(playlist);
tr.commit();
Multithreading.runAsync(() -> pruneUnusedPlaylistVideos());
Multithreading.runAsync(ResponseHelper::pruneUnusedPlaylistVideos);
}
return mapper.writeValueAsBytes(new AcceptedResponse());