diff options
| author | Samantaz Fox <coding@samantaz.fr> | 2023-05-23 19:31:19 +0200 |
|---|---|---|
| committer | Samantaz Fox <coding@samantaz.fr> | 2023-05-23 19:31:19 +0200 |
| commit | 1333e6db264b39516ec2f6897cf8410db368bf9e (patch) | |
| tree | 15e19ab066cdf211d5003c699ab729aad6375fae | |
| parent | 3a54e9556b0cd28fd224db5801f8141a68108c13 (diff) | |
| parent | d7285992517c98a276e325f83e1b7584dac3c498 (diff) | |
| download | invidious-1333e6db264b39516ec2f6897cf8410db368bf9e.tar.gz invidious-1333e6db264b39516ec2f6897cf8410db368bf9e.tar.bz2 invidious-1333e6db264b39516ec2f6897cf8410db368bf9e.zip | |
API: Add hashtag endpoint (#3692)
| -rw-r--r-- | src/invidious/routes/api/v1/search.cr | 28 | ||||
| -rw-r--r-- | src/invidious/routing.cr | 1 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/invidious/routes/api/v1/search.cr b/src/invidious/routes/api/v1/search.cr index 21451d33..9fb283c2 100644 --- a/src/invidious/routes/api/v1/search.cr +++ b/src/invidious/routes/api/v1/search.cr @@ -55,4 +55,32 @@ module Invidious::Routes::API::V1::Search return error_json(500, ex) end end + + def self.hashtag(env) + hashtag = env.params.url["hashtag"] + + page = env.params.query["page"]?.try &.to_i? || 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 9e2ade3d..72ee9194 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 |
