mirror of
https://github.com/iv-org/invidious.git
synced 2024-12-28 11:00:24 +05:30
Add format=json for reddit comments
This commit is contained in:
parent
3ec684ae71
commit
454b1662b7
@ -2014,16 +2014,24 @@ get "/api/v1/comments/:id" do |env|
|
|||||||
content_html = fill_links(content_html, "https", "www.reddit.com")
|
content_html = fill_links(content_html, "https", "www.reddit.com")
|
||||||
content_html = replace_links(content_html)
|
content_html = replace_links(content_html)
|
||||||
rescue ex
|
rescue ex
|
||||||
|
comments = nil
|
||||||
reddit_thread = nil
|
reddit_thread = nil
|
||||||
content_html = ""
|
content_html = ""
|
||||||
end
|
end
|
||||||
|
|
||||||
if !reddit_thread
|
if !reddit_thread || !comments
|
||||||
halt env, status_code: 404
|
halt env, status_code: 404
|
||||||
end
|
end
|
||||||
|
|
||||||
env.response.content_type = "application/json"
|
env.response.content_type = "application/json"
|
||||||
next {"title" => reddit_thread.title,
|
|
||||||
|
if format == "json"
|
||||||
|
reddit_thread = JSON.parse(reddit_thread.to_json).as_h
|
||||||
|
reddit_thread["comments"] = JSON.parse(comments.to_json)
|
||||||
|
next reddit_thread.to_json
|
||||||
|
else
|
||||||
|
next {
|
||||||
|
"title" => reddit_thread.title,
|
||||||
"permalink" => reddit_thread.permalink,
|
"permalink" => reddit_thread.permalink,
|
||||||
"contentHtml" => content_html,
|
"contentHtml" => content_html,
|
||||||
}.to_json
|
}.to_json
|
||||||
|
@ -191,7 +191,7 @@ function get_youtube_replies(target) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function get_reddit_comments() {
|
function get_reddit_comments() {
|
||||||
var url = "/api/v1/comments/<%= video.id %>?source=reddit";
|
var url = "/api/v1/comments/<%= video.id %>?source=reddit&format=html";
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.responseType = "json";
|
xhr.responseType = "json";
|
||||||
xhr.timeout = 20000;
|
xhr.timeout = 20000;
|
||||||
|
Loading…
Reference in New Issue
Block a user