Add support for post page

This commit is contained in:
ChunkyProgrammer
2023-07-19 12:35:22 -07:00
parent bb14f79496
commit e3c365f3d6
14 changed files with 416 additions and 167 deletions

View File

@@ -159,6 +159,11 @@ module Invidious::Routes::Channels
end
locale, user, subscriptions, continuation, ucid, channel = data
# redirect to post page
if lb = env.params.query["lb"]?
env.redirect "/post/#{lb}?ucid=#{ucid}"
end
thin_mode = env.params.query["thin_mode"]? || env.get("preferences").as(Preferences).thin_mode
thin_mode = thin_mode == "true"
@@ -187,6 +192,38 @@ module Invidious::Routes::Channels
templated "community"
end
def self.post(env)
# /post/{postId}
id = env.params.url["id"]
ucid = env.params.query["ucid"]?
prefs = env.get("preferences").as(Preferences)
locale = prefs.locale
region = env.params.query["region"]? || prefs.region
thin_mode = env.params.query["thin_mode"]? || prefs.thin_mode
thin_mode = thin_mode == "true"
client_config = YoutubeAPI::ClientConfig.new(region: region)
if !ucid.nil?
ucid = ucid.to_s
post_response = fetch_channel_community_post(ucid, id, locale, "json", thin_mode)
else
# resolve the url to get the author's UCID
response = YoutubeAPI.resolve_url("https://www.youtube.com/post/#{id}")
return error_template(400, "Invalid post ID") if response["error"]?
ucid = response.dig("endpoint", "browseEndpoint", "browseId").as_s
params = response.dig("endpoint", "browseEndpoint", "params").as_s
post_response = fetch_channel_community_post(ucid, id, locale, "json", thin_mode, params: params)
end
post_response = JSON.parse(post_response)
templated "post"
end
def self.channels(env)
data = self.fetch_basic_information(env)
return data if !data.is_a?(Tuple)