mirror of
https://github.com/iv-org/invidious.git
synced 2024-12-24 01:00:35 +05:30
Don't pass HTTP client in args
This commit is contained in:
parent
843606db65
commit
d0b30ad977
@ -152,8 +152,7 @@ before_all do |env|
|
||||
end
|
||||
else
|
||||
begin
|
||||
client = make_client(YT_URL)
|
||||
user = get_user(sid, client, headers, PG_DB, false)
|
||||
user = get_user(sid, headers, PG_DB, false)
|
||||
|
||||
challenge, token = create_response(user.email, "sign_out", HMAC_KEY, PG_DB, 1.week)
|
||||
env.set "challenge", challenge
|
||||
@ -825,8 +824,7 @@ post "/login" do |env|
|
||||
|
||||
sid = login.cookies["SID"].value
|
||||
|
||||
client = make_client(YT_URL)
|
||||
user = get_user(sid, client, headers, PG_DB)
|
||||
user = get_user(sid, headers, PG_DB)
|
||||
|
||||
# We are now logged in
|
||||
|
||||
@ -1286,8 +1284,7 @@ get "/subscription_manager" do |env|
|
||||
headers = HTTP::Headers.new
|
||||
headers["Cookie"] = env.request.headers["Cookie"]
|
||||
|
||||
client = make_client(YT_URL)
|
||||
user = get_user(user.id[0], client, headers, PG_DB)
|
||||
user = get_user(user.id[0], headers, PG_DB)
|
||||
end
|
||||
|
||||
action_takeout = env.params.query["action_takeout"]?.try &.to_i?
|
||||
@ -1297,12 +1294,10 @@ get "/subscription_manager" do |env|
|
||||
format = env.params.query["format"]?
|
||||
format ||= "rss"
|
||||
|
||||
client = make_client(YT_URL)
|
||||
|
||||
subscriptions = [] of InvidiousChannel
|
||||
user.subscriptions.each do |ucid|
|
||||
begin
|
||||
subscriptions << get_channel(ucid, client, PG_DB, false)
|
||||
subscriptions << get_channel(ucid, PG_DB, false)
|
||||
rescue ex
|
||||
next
|
||||
end
|
||||
@ -1391,8 +1386,7 @@ post "/data_control" do |env|
|
||||
|
||||
user.subscriptions.select! do |ucid|
|
||||
begin
|
||||
client = make_client(YT_URL)
|
||||
get_channel(ucid, client, PG_DB, false, false)
|
||||
get_channel(ucid, PG_DB, false, false)
|
||||
true
|
||||
rescue ex
|
||||
false
|
||||
@ -1421,8 +1415,7 @@ post "/data_control" do |env|
|
||||
|
||||
user.subscriptions.select! do |ucid|
|
||||
begin
|
||||
client = make_client(YT_URL)
|
||||
get_channel(ucid, client, PG_DB, false, false)
|
||||
get_channel(ucid, PG_DB, false, false)
|
||||
true
|
||||
rescue ex
|
||||
false
|
||||
@ -1438,8 +1431,7 @@ post "/data_control" do |env|
|
||||
|
||||
user.subscriptions.select! do |ucid|
|
||||
begin
|
||||
client = make_client(YT_URL)
|
||||
get_channel(ucid, client, PG_DB, false, false)
|
||||
get_channel(ucid, PG_DB, false, false)
|
||||
true
|
||||
rescue ex
|
||||
false
|
||||
@ -1456,8 +1448,7 @@ post "/data_control" do |env|
|
||||
|
||||
user.subscriptions.each do |ucid|
|
||||
begin
|
||||
client = make_client(YT_URL)
|
||||
get_channel(ucid, client, PG_DB, false, false)
|
||||
get_channel(ucid, PG_DB, false, false)
|
||||
rescue ex
|
||||
next
|
||||
end
|
||||
@ -1482,8 +1473,7 @@ post "/data_control" do |env|
|
||||
|
||||
user.subscriptions.select! do |ucid|
|
||||
begin
|
||||
client = make_client(YT_URL)
|
||||
get_channel(ucid, client, PG_DB, false, false)
|
||||
get_channel(ucid, PG_DB, false, false)
|
||||
true
|
||||
rescue ex
|
||||
false
|
||||
@ -1567,8 +1557,7 @@ get "/subscription_ajax" do |env|
|
||||
if !user.subscriptions.includes? channel_id
|
||||
PG_DB.exec("UPDATE users SET subscriptions = array_append(subscriptions,$1) WHERE email = $2", channel_id, email)
|
||||
|
||||
client = make_client(YT_URL)
|
||||
get_channel(channel_id, client, PG_DB, false, false)
|
||||
get_channel(channel_id, PG_DB, false, false)
|
||||
end
|
||||
when .starts_with? "action_remove"
|
||||
PG_DB.exec("UPDATE users SET subscriptions = array_remove(subscriptions,$1) WHERE email = $2", channel_id, email)
|
||||
@ -1708,8 +1697,7 @@ get "/feed/subscriptions" do |env|
|
||||
headers["Cookie"] = env.request.headers["Cookie"]
|
||||
|
||||
if !user.password
|
||||
client = make_client(YT_URL)
|
||||
user = get_user(user.id[0], client, headers, PG_DB)
|
||||
user = get_user(user.id[0], headers, PG_DB)
|
||||
end
|
||||
|
||||
max_results = preferences.max_results
|
||||
|
@ -21,7 +21,9 @@ class ChannelVideo
|
||||
})
|
||||
end
|
||||
|
||||
def get_channel(id, client, db, refresh = true, pull_all_videos = true)
|
||||
def get_channel(id, db, refresh = true, pull_all_videos = true)
|
||||
client = make_client(YT_URL)
|
||||
|
||||
if db.query_one?("SELECT EXISTS (SELECT true FROM channels WHERE id = $1)", id, as: Bool)
|
||||
channel = db.query_one("SELECT * FROM channels WHERE id = $1", id, as: InvidiousChannel)
|
||||
|
||||
|
@ -116,12 +116,12 @@ class Preferences
|
||||
})
|
||||
end
|
||||
|
||||
def get_user(sid, client, headers, db, refresh = true)
|
||||
def get_user(sid, headers, db, refresh = true)
|
||||
if db.query_one?("SELECT EXISTS (SELECT true FROM users WHERE $1 = ANY(id))", sid, as: Bool)
|
||||
user = db.query_one("SELECT * FROM users WHERE $1 = ANY(id)", sid, as: User)
|
||||
|
||||
if refresh && Time.now - user.updated > 1.minute
|
||||
user = fetch_user(sid, client, headers, db)
|
||||
user = fetch_user(sid, headers, db)
|
||||
user_array = user.to_a
|
||||
|
||||
user_array[5] = user_array[5].to_json
|
||||
@ -140,7 +140,7 @@ def get_user(sid, client, headers, db, refresh = true)
|
||||
end
|
||||
end
|
||||
else
|
||||
user = fetch_user(sid, client, headers, db)
|
||||
user = fetch_user(sid, headers, db)
|
||||
user_array = user.to_a
|
||||
|
||||
user_array[5] = user_array[5].to_json
|
||||
@ -162,7 +162,8 @@ def get_user(sid, client, headers, db, refresh = true)
|
||||
return user
|
||||
end
|
||||
|
||||
def fetch_user(sid, client, headers, db)
|
||||
def fetch_user(sid, headers, db)
|
||||
client = make_client(YT_URL)
|
||||
feed = client.get("/subscription_manager?disable_polymer=1", headers)
|
||||
feed = XML.parse_html(feed.body)
|
||||
|
||||
@ -172,7 +173,7 @@ def fetch_user(sid, client, headers, db)
|
||||
channel_id = channel["href"].lstrip("/channel/")
|
||||
|
||||
begin
|
||||
channel = get_channel(channel_id, client, db, false, false)
|
||||
channel = get_channel(channel_id, db, false, false)
|
||||
channels << channel.id
|
||||
rescue ex
|
||||
next
|
||||
|
Loading…
Reference in New Issue
Block a user