mirror of
https://github.com/iv-org/invidious.git
synced 2024-12-30 01:36:21 -05:00
Fix comments endpoint for videos that have no comments
This commit is contained in:
parent
6aeb508f29
commit
2b911aabc4
@ -563,12 +563,21 @@ get "/api/v1/comments/:id" do |env|
|
|||||||
else
|
else
|
||||||
body = response["itemSectionContinuation"]
|
body = response["itemSectionContinuation"]
|
||||||
end
|
end
|
||||||
contents = body["contents"]
|
contents = body["contents"]?
|
||||||
|
if !contents
|
||||||
|
env.response.content_type = "application/json"
|
||||||
|
|
||||||
|
if format == "json"
|
||||||
|
next {"comments" => [] of String}.to_json
|
||||||
|
else
|
||||||
|
next {"content_html" => ""}.to_json
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
comments = JSON.build do |json|
|
comments = JSON.build do |json|
|
||||||
json.object do
|
json.object do
|
||||||
if body["header"]?
|
if body["header"]?
|
||||||
comment_count = body["header"]["commentsHeaderRenderer"]["countText"]["simpleText"].as_s.rchop(" Comment").delete("s,").to_i
|
comment_count = body["header"]["commentsHeaderRenderer"]["countText"]["simpleText"].as_s.delete("Comments,").to_i
|
||||||
json.field "commentCount", comment_count
|
json.field "commentCount", comment_count
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user