From d6fb5c03b72b40bf7bd71f8023c71c76ea41f53d Mon Sep 17 00:00:00 2001 From: ChunkyProgrammer <78101139+ChunkyProgrammer@users.noreply.github.com> Date: Thu, 16 Mar 2023 11:03:07 -0400 Subject: [PATCH 1/2] add hashtag endpoint --- src/invidious/routes/api/v1/search.cr | 30 +++++++++++++++++++++++++++ src/invidious/routing.cr | 1 + 2 files changed, 31 insertions(+) diff --git a/src/invidious/routes/api/v1/search.cr b/src/invidious/routes/api/v1/search.cr index 21451d332..0bf74bc3f 100644 --- a/src/invidious/routes/api/v1/search.cr +++ b/src/invidious/routes/api/v1/search.cr @@ -55,4 +55,34 @@ module Invidious::Routes::API::V1::Search return error_json(500, ex) end end + + def self.hashtag(env) + hashtag = env.params.url["hashtag"] + + # page does not change anything. + # page = env.params.query["page"]?.try &.to_i?|| 1 + + page = 1 + locale = env.get("preferences").as(Preferences).locale + region = env.params.query["region"]? + env.response.content_type = "application/json" + + begin + results = Invidious::Hashtag.fetch(hashtag, page, region) + rescue ex + return error_json(400, ex) + end + + JSON.build do |json| + json.object do + json.field "results" do + json.array do + results.each do |item| + item.to_json(locale, json) + end + end + end + end + end + end end diff --git a/src/invidious/routing.cr b/src/invidious/routing.cr index 9e2ade3df..72ee9194b 100644 --- a/src/invidious/routing.cr +++ b/src/invidious/routing.cr @@ -243,6 +243,7 @@ module Invidious::Routing # Search get "/api/v1/search", {{namespace}}::Search, :search get "/api/v1/search/suggestions", {{namespace}}::Search, :search_suggestions + get "/api/v1/hashtag/:hashtag", {{namespace}}::Search, :hashtag # Authenticated From d7285992517c98a276e325f83e1b7584dac3c498 Mon Sep 17 00:00:00 2001 From: chunky programmer <78101139+ChunkyProgrammer@users.noreply.github.com> Date: Sun, 14 May 2023 15:20:59 -0400 Subject: [PATCH 2/2] add page parameter --- src/invidious/routes/api/v1/search.cr | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/invidious/routes/api/v1/search.cr b/src/invidious/routes/api/v1/search.cr index 0bf74bc3f..9fb283c23 100644 --- a/src/invidious/routes/api/v1/search.cr +++ b/src/invidious/routes/api/v1/search.cr @@ -59,10 +59,8 @@ module Invidious::Routes::API::V1::Search def self.hashtag(env) hashtag = env.params.url["hashtag"] - # page does not change anything. - # page = env.params.query["page"]?.try &.to_i?|| 1 + page = env.params.query["page"]?.try &.to_i? || 1 - page = 1 locale = env.get("preferences").as(Preferences).locale region = env.params.query["region"]? env.response.content_type = "application/json"