diff options
| author | Omar Roth <omarroth@hotmail.com> | 2018-09-06 10:19:28 -0500 |
|---|---|---|
| committer | Omar Roth <omarroth@hotmail.com> | 2018-09-06 10:19:28 -0500 |
| commit | 454b1662b7d38e0e5120104c1f62f5297a01af1d (patch) | |
| tree | 6a3081860a6e4e5b34fabd65198124b861acf719 | |
| parent | 3ec684ae710529f681ea731a3cbd5f6fc9bee6a6 (diff) | |
| download | invidious-454b1662b7d38e0e5120104c1f62f5297a01af1d.tar.gz invidious-454b1662b7d38e0e5120104c1f62f5297a01af1d.tar.bz2 invidious-454b1662b7d38e0e5120104c1f62f5297a01af1d.zip | |
Add format=json for reddit comments
| -rw-r--r-- | src/invidious.cr | 12 | ||||
| -rw-r--r-- | src/invidious/views/watch.ecr | 2 |
2 files changed, 11 insertions, 3 deletions
diff --git a/src/invidious.cr b/src/invidious.cr index a982f708..ebd1b76a 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -2014,16 +2014,24 @@ get "/api/v1/comments/:id" do |env| content_html = fill_links(content_html, "https", "www.reddit.com") content_html = replace_links(content_html) rescue ex + comments = nil reddit_thread = nil content_html = "" end - if !reddit_thread + if !reddit_thread || !comments halt env, status_code: 404 end 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, "contentHtml" => content_html, }.to_json diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr index d52d9092..296a545c 100644 --- a/src/invidious/views/watch.ecr +++ b/src/invidious/views/watch.ecr @@ -191,7 +191,7 @@ function get_youtube_replies(target) { } 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(); xhr.responseType = "json"; xhr.timeout = 20000; |
