Make use of Search::Query/Filters and associated HTML generator

This commit is contained in:
Samantaz Fox
2022-03-26 20:15:02 +01:00
parent a813955ad3
commit d93a7b315d
10 changed files with 87 additions and 331 deletions

View File

@@ -251,18 +251,22 @@ module Invidious::Routes::API::V1::Channels
def self.search(env)
locale = env.get("preferences").as(Preferences).locale
region = env.params.query["region"]?
env.response.content_type = "application/json"
ucid = env.params.url["ucid"]
query = Invidious::Search::Query.new(env.params.query, :channel, region)
query = env.params.query["q"]?
query ||= ""
# Required because we can't (yet) pass multiple parameter to the
# `Search::Query` initializer (in this case, an URL segment)
query.channel = env.params.url["ucid"]
page = env.params.query["page"]?.try &.to_i?
page ||= 1
begin
search_results = query.process
rescue ex
return error_json(400, ex)
end
search_results = Invidious::Search::Processors.channel(query, page, ucid)
JSON.build do |json|
json.array do
search_results.each do |item|

View File

@@ -5,34 +5,14 @@ module Invidious::Routes::API::V1::Search
env.response.content_type = "application/json"
query = env.params.query["q"]?
query ||= ""
page = env.params.query["page"]?.try &.to_i?
page ||= 1
sort_by = env.params.query["sort_by"]?.try &.downcase
sort_by ||= "relevance"
date = env.params.query["date"]?.try &.downcase
date ||= ""
duration = env.params.query["duration"]?.try &.downcase
duration ||= ""
features = env.params.query["features"]?.try &.split(",").map(&.downcase)
features ||= [] of String
content_type = env.params.query["type"]?.try &.downcase
content_type ||= "video"
query = Invidious::Search::Query.new(env.params.query, :regular, region)
begin
search_params = produce_search_params(page, sort_by, date, content_type, duration, features)
search_results = query.process
rescue ex
return error_json(400, ex)
end
search_results = search(query, search_params, region)
JSON.build do |json|
json.array do
search_results.each do |item|