Skip to content

Commit

Permalink
API: Add hashtag endpoint (iv-org#3692)
Browse files Browse the repository at this point in the history
  • Loading branch information
SamantazFox committed May 23, 2023
2 parents 3a54e95 + d728599 commit 1333e6d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/invidious/routes/api/v1/search.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/invidious/routing.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 1333e6d

Please sign in to comment.