mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Implement OpenSearch api.
This commit is contained in:
parent
b63786a15e
commit
f731308dcc
2 changed files with 17 additions and 0 deletions
|
@ -145,6 +145,7 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher {
|
|||
} catch (Exception e) {
|
||||
return getErrorResponse(e, request.getPath());
|
||||
}
|
||||
// TODO: Replace with opensearch, below, for caching reasons.
|
||||
})).map(GET, "/suggestions", AsyncServlet.ofBlocking(executor, request -> {
|
||||
try {
|
||||
return getJsonResponse(ResponseHelper.suggestionsResponse(request.getQueryParameter("query")),
|
||||
|
@ -152,6 +153,14 @@ public class ServerLauncher extends MultithreadedHttpServerLauncher {
|
|||
} catch (Exception e) {
|
||||
return getErrorResponse(e, request.getPath());
|
||||
}
|
||||
})).map(GET, "/opensearch/suggestions", AsyncServlet.ofBlocking(executor, request -> {
|
||||
try {
|
||||
return getJsonResponse(
|
||||
ResponseHelper.opensearchSuggestionsResponse(request.getQueryParameter("query")),
|
||||
"public, max-age=600");
|
||||
} catch (Exception e) {
|
||||
return getErrorResponse(e, request.getPath());
|
||||
}
|
||||
})).map(GET, "/search", AsyncServlet.ofBlocking(executor, request -> {
|
||||
try {
|
||||
return getJsonResponse(ResponseHelper.searchResponse(request.getQueryParameter("q"),
|
||||
|
|
|
@ -382,6 +382,14 @@ public class ResponseHelper {
|
|||
|
||||
}
|
||||
|
||||
public static final byte[] opensearchSuggestionsResponse(String query)
|
||||
throws JsonProcessingException, IOException, ExtractionException {
|
||||
|
||||
return Constants.mapper.writeValueAsBytes(
|
||||
Arrays.asList(query, YOUTUBE_SERVICE.getSuggestionExtractor().suggestionList(query)));
|
||||
|
||||
}
|
||||
|
||||
public static final byte[] searchResponse(String q, String filter)
|
||||
throws IOException, ExtractionException, InterruptedException {
|
||||
|
||||
|
|
Loading…
Reference in a new issue