mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-30 02:32:56 +05:30
Refactor HTTP::Client calls into make_client
This commit is contained in:
parent
ae7b5fac74
commit
b6fff53b21
@ -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
|
||||
|
||||
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)
|
||||
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|
|
||||
|
Loading…
Reference in New Issue
Block a user