mirror of
				https://github.com/iv-org/invidious.git
				synced 2025-10-31 12:42:09 +00:00 
			
		
		
		
	Refactor HTTP::Client calls into make_client
This commit is contained in:
		| @@ -45,7 +45,7 @@ ARCHIVE_URL     = URI.parse("https://archive.org") | ||||
| LOGIN_URL       = URI.parse("https://accounts.google.com") | ||||
| PUBSUB_URL      = URI.parse("https://pubsubhubbub.appspot.com") | ||||
| REDDIT_URL      = URI.parse("https://www.reddit.com") | ||||
| TEXTCAPTCHA_URL = URI.parse("http://textcaptcha.com/omarroth@protonmail.com.json") | ||||
| TEXTCAPTCHA_URL = URI.parse("http://textcaptcha.com") | ||||
| YT_URL          = URI.parse("https://www.youtube.com") | ||||
| CHARS_SAFE      = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" | ||||
| CURRENT_BRANCH  = {{ "#{`git branch | sed -n '/\* /s///p'`.strip}" }} | ||||
| @@ -2972,7 +2972,7 @@ get "/api/v1/annotations/:id" do |env| | ||||
|         env.response.status_code = location.status_code | ||||
|       end | ||||
|  | ||||
|       response = HTTP::Client.get(URI.parse(location.headers["Location"])) | ||||
|       response = make_client(URI.parse(location.headers["Location"])).get(location.headers["Location"]) | ||||
|  | ||||
|       if response.body.empty? | ||||
|         env.response.status_code = 404 | ||||
|   | ||||
| @@ -619,6 +619,8 @@ def cache_annotation(db, id, annotations) | ||||
|     end | ||||
|   end | ||||
|  | ||||
|   # TODO: Update on conflict? | ||||
|   db.exec("INSERT INTO annotations VALUES ($1, $2) ON CONFLICT DO NOTHING", id, annotations) | ||||
|   if has_legacy_annotations | ||||
|     # TODO: Update on conflict? | ||||
|     db.exec("INSERT INTO annotations VALUES ($1, $2) ON CONFLICT DO NOTHING", id, annotations) | ||||
|   end | ||||
| end | ||||
|   | ||||
| @@ -18,13 +18,18 @@ def elapsed_text(elapsed) | ||||
|   "#{(millis * 1000).round(2)}µs" | ||||
| end | ||||
|  | ||||
| def make_client(url, proxies = {} of String => Array({ip: String, port: Int32}), region = nil) | ||||
|   context = OpenSSL::SSL::Context::Client.new | ||||
|   context.add_options( | ||||
|     OpenSSL::SSL::Options::ALL | | ||||
|     OpenSSL::SSL::Options::NO_SSL_V2 | | ||||
|     OpenSSL::SSL::Options::NO_SSL_V3 | ||||
|   ) | ||||
| def make_client(url : URI, proxies = {} of String => Array({ip: String, port: Int32}), region = nil) | ||||
|   context = nil | ||||
|  | ||||
|   if url.scheme == "https" | ||||
|     context = OpenSSL::SSL::Context::Client.new | ||||
|     context.add_options( | ||||
|       OpenSSL::SSL::Options::ALL | | ||||
|       OpenSSL::SSL::Options::NO_SSL_V2 | | ||||
|       OpenSSL::SSL::Options::NO_SSL_V3 | ||||
|     ) | ||||
|   end | ||||
|  | ||||
|   client = HTTPClient.new(url, context) | ||||
|   client.read_timeout = 10.seconds | ||||
|   client.connect_timeout = 10.seconds | ||||
|   | ||||
| @@ -331,7 +331,7 @@ def generate_captcha(key, db) | ||||
| end | ||||
|  | ||||
| def generate_text_captcha(key, db) | ||||
|   response = HTTP::Client.get(TEXTCAPTCHA_URL).body | ||||
|   response = make_client(TEXTCAPTCHA_URL).get("/omarroth@protonmail.com.json").body | ||||
|   response = JSON.parse(response) | ||||
|  | ||||
|   tokens = response["a"].as_a.map do |answer| | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Omar Roth
					Omar Roth