mirror of
https://git.nadeko.net/Fijxu/invidious.git
synced 2025-12-19 19:38:51 +00:00
Move DB queries related to 'users' in a separate module (1/2)
This commit is contained in:
@@ -94,7 +94,7 @@ module Invidious::Routes::API::V1::Authenticated
|
||||
|
||||
if !user.subscriptions.includes? ucid
|
||||
get_channel(ucid, PG_DB, false, false)
|
||||
PG_DB.exec("UPDATE users SET feed_needs_update = true, subscriptions = array_append(subscriptions,$1) WHERE email = $2", ucid, user.email)
|
||||
Invidious::Database::Users.subscribe_channel(user, ucid)
|
||||
end
|
||||
|
||||
# For Google accounts, access tokens don't have enough information to
|
||||
@@ -110,7 +110,7 @@ module Invidious::Routes::API::V1::Authenticated
|
||||
|
||||
ucid = env.params.url["ucid"]
|
||||
|
||||
PG_DB.exec("UPDATE users SET feed_needs_update = true, subscriptions = array_remove(subscriptions, $1) WHERE email = $2", ucid, user.email)
|
||||
Invidious::Database::Users.unsubscribe_channel(user, ucid)
|
||||
|
||||
env.response.status_code = 204
|
||||
end
|
||||
|
||||
@@ -220,7 +220,7 @@ module Invidious::Routes::Feeds
|
||||
haltf env, status_code: 403
|
||||
end
|
||||
|
||||
user = PG_DB.query_one?("SELECT * FROM users WHERE token = $1", token.strip, as: User)
|
||||
user = Invidious::Database::Users.select(token: token.strip)
|
||||
if !user
|
||||
haltf env, status_code: 403
|
||||
end
|
||||
|
||||
@@ -327,7 +327,7 @@ module Invidious::Routes::Login
|
||||
return error_template(401, "Password is a required field")
|
||||
end
|
||||
|
||||
user = PG_DB.query_one?("SELECT * FROM users WHERE email = $1", email, as: User)
|
||||
user = Invidious::Database::Users.select(email: email)
|
||||
|
||||
if user
|
||||
if !user.password
|
||||
@@ -449,12 +449,7 @@ module Invidious::Routes::Login
|
||||
end
|
||||
end
|
||||
|
||||
user_array = user.to_a
|
||||
user_array[4] = user_array[4].to_json # User preferences
|
||||
|
||||
args = arg_array(user_array)
|
||||
|
||||
PG_DB.exec("INSERT INTO users VALUES (#{args})", args: user_array)
|
||||
Invidious::Database::Users.insert(user)
|
||||
Invidious::Database::SessionIDs.insert(sid, email)
|
||||
|
||||
view_name = "subscriptions_#{sha256(user.email)}"
|
||||
|
||||
@@ -76,7 +76,7 @@ module Invidious::Routes::Watch
|
||||
env.params.query.delete_all("iv_load_policy")
|
||||
|
||||
if watched && !watched.includes? id
|
||||
PG_DB.exec("UPDATE users SET watched = array_append(watched, $1) WHERE email = $2", id, user.as(User).email)
|
||||
Invidious::Database::Users.mark_watched(user.as(User), id)
|
||||
end
|
||||
|
||||
if notifications && notifications.includes? id
|
||||
|
||||
Reference in New Issue
Block a user