diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 000000000..3f28c2b76 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +custom: https://invidious.io/donate/ diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index c04852663..4c1a63307 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -7,9 +7,16 @@ assignees: '' --- - - - + + **Describe the bug** diff --git a/README.md b/README.md index f46f2d9db..0f0c59e0e 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,8 @@ Website  •  Instances list +  •  + FAQ  •  Documentation  •  diff --git a/locales/en-US.json b/locales/en-US.json index 91af3d723..f733f7db1 100644 --- a/locales/en-US.json +++ b/locales/en-US.json @@ -430,5 +430,12 @@ "user_created_playlists": "`x` created playlists", "user_saved_playlists": "`x` saved playlists", "Video unavailable": "Video unavailable", - "preferences_save_player_pos_label": "Save playback position: " + "preferences_save_player_pos_label": "Save playback position: ", + "crash_page_you_found_a_bug": "It looks like you found a bug in Invidious!", + "crash_page_before_reporting": "Before reporting a bug, make sure that you have:", + "crash_page_refresh": "tried to refresh the page", + "crash_page_switch_instance": "tried to use another instance", + "crash_page_read_the_faq": "read the Frenquently Asked Questions (FAQ)", + "crash_page_search_issue": "searched for existing issues on Github", + "crash_page_report_issue": "If none of the above helped, please open a new issue on GitHub (preferably in English) and include the following text in your message (do NOT translate that text):" } diff --git a/src/invidious/comments.cr b/src/invidious/comments.cr index 256a294eb..dda924402 100644 --- a/src/invidious/comments.cr +++ b/src/invidious/comments.cr @@ -268,18 +268,20 @@ def fetch_reddit_comments(id, sort_by = "confidence") headers = HTTP::Headers{"User-Agent" => "web:invidious:v#{CURRENT_VERSION} (by github.com/iv-org/invidious)"} # TODO: Use something like #479 for a static list of instances to use here - query = "(url:3D#{id}%20OR%20url:#{id})%20(site:invidio.us%20OR%20site:youtube.com%20OR%20site:youtu.be)" - search_results = client.get("/search.json?q=#{query}", headers) + query = URI::Params.encode({q: "(url:3D#{id} OR url:#{id}) AND (site:invidio.us OR site:youtube.com OR site:youtu.be)"}) + search_results = client.get("/search.json?#{query}", headers) if search_results.status_code == 200 search_results = RedditThing.from_json(search_results.body) # For videos that have more than one thread, choose the one with the highest score - thread = search_results.data.as(RedditListing).children.sort_by { |child| child.data.as(RedditLink).score }[-1] - thread = thread.data.as(RedditLink) - - result = client.get("/r/#{thread.subreddit}/comments/#{thread.id}.json?limit=100&sort=#{sort_by}", headers).body - result = Array(RedditThing).from_json(result) + threads = search_results.data.as(RedditListing).children + thread = threads.max_by?(&.data.as(RedditLink).score).try(&.data.as(RedditLink)) + result = thread.try do |t| + body = client.get("/r/#{t.subreddit}/comments/#{t.id}.json?limit=100&sort=#{sort_by}", headers).body + Array(RedditThing).from_json(body) + end + result ||= [] of RedditThing elsif search_results.status_code == 302 # Previously, if there was only one result then the API would redirect to that result. # Now, it appears it will still return a listing so this section is likely unnecessary. @@ -294,7 +296,8 @@ def fetch_reddit_comments(id, sort_by = "confidence") client.close - comments = result[1].data.as(RedditListing).children + comments = result[1]?.try(&.data.as(RedditListing).children) + comments ||= [] of RedditThing return comments, thread end diff --git a/src/invidious/helpers/errors.cr b/src/invidious/helpers/errors.cr index d10762c52..26c386696 100644 --- a/src/invidious/helpers/errors.cr +++ b/src/invidious/helpers/errors.cr @@ -26,22 +26,53 @@ def error_template_helper(env : HTTP::Server::Context, locale : String?, status_ if exception.is_a?(InfoException) return error_template_helper(env, locale, status_code, exception.message || "") end + env.response.content_type = "text/html" env.response.status_code = status_code - issue_template = %(Title: `#{exception.message} (#{exception.class})`) + + issue_title = "#{exception.message} (#{exception.class})" + + issue_template = %(Title: `#{issue_title}`) issue_template += %(\nDate: `#{Time::Format::ISO_8601_DATE_TIME.format(Time.utc)}`) issue_template += %(\nRoute: `#{env.request.resource}`) issue_template += %(\nVersion: `#{SOFTWARE["version"]} @ #{SOFTWARE["branch"]}`) # issue_template += github_details("Preferences", env.get("preferences").as(Preferences).to_pretty_json) issue_template += github_details("Backtrace", exception.inspect_with_backtrace) + + # URLs for the error message below + url_faq = "https://github.com/iv-org/documentation/blob/master/FAQ.md" + url_search_issues = "https://github.com/iv-org/invidious/issues" + + url_switch = "https://redirect.invidious.io" + env.request.resource + + url_new_issue = "https://github.com/iv-org/invidious/issues/new" + url_new_issue += "?labels=bug&template=bug_report.md&title=" + url_new_issue += URI.encode_www_form("[Bug] " + issue_title) + error_message = <<-END_HTML - Looks like you've found a bug in Invidious. Please open a new issue - on GitHub - and include the following text in your message: -
#{issue_template}
+
+

#{translate(locale, "crash_page_you_found_a_bug")}

+

+ +

#{translate(locale, "crash_page_before_reporting")}

+ + +
+

#{translate(locale, "crash_page_report_issue", url_new_issue)}

+ + +
#{issue_template}
+
END_HTML - next_steps = error_redirect_helper(env, locale) + # Don't show the usual "next steps" widget. The same options are + # proposed above the error message, just worded differently. + next_steps = "" return templated "error" end diff --git a/src/invidious/routes/api/v1/videos.cr b/src/invidious/routes/api/v1/videos.cr index 4d244e7f8..3a013ba08 100644 --- a/src/invidious/routes/api/v1/videos.cr +++ b/src/invidious/routes/api/v1/videos.cr @@ -330,18 +330,13 @@ module Invidious::Routes::API::V1::Videos begin comments, reddit_thread = fetch_reddit_comments(id, sort_by: sort_by) - content_html = template_reddit_comments(comments, locale) - - 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 || !comments - haltf env, 404 + return error_json(404, "No reddit threads found") end if format == "json" @@ -350,6 +345,9 @@ module Invidious::Routes::API::V1::Videos return reddit_thread.to_json else + content_html = template_reddit_comments(comments, locale) + content_html = fill_links(content_html, "https", "www.reddit.com") + content_html = replace_links(content_html) response = { "title" => reddit_thread.title, "permalink" => reddit_thread.permalink,