From 90edf2fc60ccf03e3efdeba8f1e1e77d5df8e099 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Tue, 30 Apr 2019 20:48:48 -0500 Subject: [PATCH] Add 'debug' topic to /api/v1/auth/notifications --- src/invidious.cr | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/invidious.cr b/src/invidious.cr index 36e6f01d..0690c1d8 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -48,6 +48,7 @@ REDDIT_URL = URI.parse("https://www.reddit.com") TEXTCAPTCHA_URL = URI.parse("http://textcaptcha.com") YT_URL = URI.parse("https://www.youtube.com") CHARS_SAFE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" +TEST_IDS = {"AgbeGFYluEA", "BaW_jenozKc", "a9LDPn-MO4I", "ddFvjfvPnqk", "iqKdEhx-dD4"} CURRENT_BRANCH = {{ "#{`git branch | sed -n '/\* /s///p'`.strip}" }} CURRENT_COMMIT = {{ "#{`git rev-list HEAD --max-count=1 --abbrev-commit`.strip}" }} CURRENT_VERSION = {{ "#{`git describe --tags --abbrev=0`.strip}" }} @@ -4282,6 +4283,39 @@ get "/api/v1/auth/notifications" do |env| begin id = 0 + if topics.includes? "debug" + spawn do + loop do + time_span = [0, 0, 0, 0] + time_span[rand(4)] = rand(30) + 5 + published = Time.now - Time::Span.new(time_span[0], time_span[1], time_span[2], time_span[3]) + video_id = TEST_IDS[rand(TEST_IDS.size)] + + video = get_video(video_id, PG_DB, proxies) + video.published = published + response = JSON.parse(video.to_json(locale, config, Kemal.config, decrypt_function)) + + if fields_text = env.params.query["fields"]? + begin + JSONFilter.filter(response, fields_text) + rescue ex + env.response.status_code = 400 + response = {"error" => ex.message} + end + end + + env.response.puts "id: #{id}" + env.response.puts "data: #{response.to_json}" + env.response.puts + env.response.flush + + id += 1 + + sleep 1.minute + end + end + end + spawn do if since topics.try &.each do |topic|