forked from midou/invidious
Move user struct to own file, under Invidious namespace
This commit is contained in:
parent
fb36155022
commit
c04f45d5e3
@ -548,7 +548,7 @@ add_handler AuthHandler.new
|
|||||||
add_handler DenyFrame.new
|
add_handler DenyFrame.new
|
||||||
add_context_storage_type(Array(String))
|
add_context_storage_type(Array(String))
|
||||||
add_context_storage_type(Preferences)
|
add_context_storage_type(Preferences)
|
||||||
add_context_storage_type(User)
|
add_context_storage_type(Invidious::User)
|
||||||
|
|
||||||
Kemal.config.logger = LOGGER
|
Kemal.config.logger = LOGGER
|
||||||
Kemal.config.host_binding = Kemal.config.host_binding != "0.0.0.0" ? Kemal.config.host_binding : CONFIG.host_binding
|
Kemal.config.host_binding = Kemal.config.host_binding != "0.0.0.0" ? Kemal.config.host_binding : CONFIG.host_binding
|
||||||
|
@ -176,7 +176,7 @@ end
|
|||||||
|
|
||||||
def process_search_query(query, page, user, region)
|
def process_search_query(query, page, user, region)
|
||||||
if user
|
if user
|
||||||
user = user.as(User)
|
user = user.as(Invidious::User)
|
||||||
view_name = "subscriptions_#{sha256(user.email)}"
|
view_name = "subscriptions_#{sha256(user.email)}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
27
src/invidious/user/user.cr
Normal file
27
src/invidious/user/user.cr
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
require "db"
|
||||||
|
|
||||||
|
struct Invidious::User
|
||||||
|
include DB::Serializable
|
||||||
|
|
||||||
|
property updated : Time
|
||||||
|
property notifications : Array(String)
|
||||||
|
property subscriptions : Array(String)
|
||||||
|
property email : String
|
||||||
|
|
||||||
|
@[DB::Field(converter: Invidious::User::PreferencesConverter)]
|
||||||
|
property preferences : Preferences
|
||||||
|
property password : String?
|
||||||
|
property token : String
|
||||||
|
property watched : Array(String)
|
||||||
|
property feed_needs_update : Bool?
|
||||||
|
|
||||||
|
module PreferencesConverter
|
||||||
|
def self.from_rs(rs)
|
||||||
|
begin
|
||||||
|
Preferences.from_json(rs.read(String))
|
||||||
|
rescue ex
|
||||||
|
Preferences.from_json("{}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -3,32 +3,6 @@ require "crypto/bcrypt/password"
|
|||||||
# Materialized views may not be defined using bound parameters (`$1` as used elsewhere)
|
# Materialized views may not be defined using bound parameters (`$1` as used elsewhere)
|
||||||
MATERIALIZED_VIEW_SQL = ->(email : String) { "SELECT cv.* FROM channel_videos cv WHERE EXISTS (SELECT subscriptions FROM users u WHERE cv.ucid = ANY (u.subscriptions) AND u.email = E'#{email.gsub({'\'' => "\\'", '\\' => "\\\\"})}') ORDER BY published DESC" }
|
MATERIALIZED_VIEW_SQL = ->(email : String) { "SELECT cv.* FROM channel_videos cv WHERE EXISTS (SELECT subscriptions FROM users u WHERE cv.ucid = ANY (u.subscriptions) AND u.email = E'#{email.gsub({'\'' => "\\'", '\\' => "\\\\"})}') ORDER BY published DESC" }
|
||||||
|
|
||||||
struct User
|
|
||||||
include DB::Serializable
|
|
||||||
|
|
||||||
property updated : Time
|
|
||||||
property notifications : Array(String)
|
|
||||||
property subscriptions : Array(String)
|
|
||||||
property email : String
|
|
||||||
|
|
||||||
@[DB::Field(converter: User::PreferencesConverter)]
|
|
||||||
property preferences : Preferences
|
|
||||||
property password : String?
|
|
||||||
property token : String
|
|
||||||
property watched : Array(String)
|
|
||||||
property feed_needs_update : Bool?
|
|
||||||
|
|
||||||
module PreferencesConverter
|
|
||||||
def self.from_rs(rs)
|
|
||||||
begin
|
|
||||||
Preferences.from_json(rs.read(String))
|
|
||||||
rescue ex
|
|
||||||
Preferences.from_json("{}")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_user(sid, headers, refresh = true)
|
def get_user(sid, headers, refresh = true)
|
||||||
if email = Invidious::Database::SessionIDs.select_email(sid)
|
if email = Invidious::Database::SessionIDs.select_email(sid)
|
||||||
user = Invidious::Database::Users.select!(email: email)
|
user = Invidious::Database::Users.select!(email: email)
|
||||||
@ -84,7 +58,7 @@ def fetch_user(sid, headers)
|
|||||||
|
|
||||||
token = Base64.urlsafe_encode(Random::Secure.random_bytes(32))
|
token = Base64.urlsafe_encode(Random::Secure.random_bytes(32))
|
||||||
|
|
||||||
user = User.new({
|
user = Invidious::User.new({
|
||||||
updated: Time.utc,
|
updated: Time.utc,
|
||||||
notifications: [] of String,
|
notifications: [] of String,
|
||||||
subscriptions: channels,
|
subscriptions: channels,
|
||||||
@ -102,7 +76,7 @@ def create_user(sid, email, password)
|
|||||||
password = Crypto::Bcrypt::Password.create(password, cost: 10)
|
password = Crypto::Bcrypt::Password.create(password, cost: 10)
|
||||||
token = Base64.urlsafe_encode(Random::Secure.random_bytes(32))
|
token = Base64.urlsafe_encode(Random::Secure.random_bytes(32))
|
||||||
|
|
||||||
user = User.new({
|
user = Invidious::User.new({
|
||||||
updated: Time.utc,
|
updated: Time.utc,
|
||||||
notifications: [] of String,
|
notifications: [] of String,
|
||||||
subscriptions: [] of String,
|
subscriptions: [] of String,
|
||||||
|
@ -252,7 +252,7 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<% if env.get?("user") && CONFIG.admins.includes? env.get?("user").as(User).email %>
|
<% if env.get?("user") && CONFIG.admins.includes? env.get?("user").as(Invidious::User).email %>
|
||||||
<legend><%= translate(locale, "preferences_category_admin") %></legend>
|
<legend><%= translate(locale, "preferences_category_admin") %></legend>
|
||||||
|
|
||||||
<div class="pure-control-group">
|
<div class="pure-control-group">
|
||||||
|
@ -52,7 +52,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="pure-u-1-4">
|
<div class="pure-u-1-4">
|
||||||
<a id="notification_ticker" title="<%= translate(locale, "Subscriptions") %>" href="/feed/subscriptions" class="pure-menu-heading">
|
<a id="notification_ticker" title="<%= translate(locale, "Subscriptions") %>" href="/feed/subscriptions" class="pure-menu-heading">
|
||||||
<% notification_count = env.get("user").as(User).notifications.size %>
|
<% notification_count = env.get("user").as(Invidious::User).notifications.size %>
|
||||||
<% if notification_count > 0 %>
|
<% if notification_count > 0 %>
|
||||||
<span id="notification_count"><%= notification_count %></span> <i class="icon ion-ios-notifications"></i>
|
<span id="notification_count"><%= notification_count %></span> <i class="icon ion-ios-notifications"></i>
|
||||||
<% else %>
|
<% else %>
|
||||||
@ -67,7 +67,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<% if env.get("preferences").as(Preferences).show_nick %>
|
<% if env.get("preferences").as(Preferences).show_nick %>
|
||||||
<div class="pure-u-1-4">
|
<div class="pure-u-1-4">
|
||||||
<span id="user_name"><%= env.get("user").as(User).email %></span>
|
<span id="user_name"><%= env.get("user").as(Invidious::User).email %></span>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<div class="pure-u-1-4">
|
<div class="pure-u-1-4">
|
||||||
|
Loading…
Reference in New Issue
Block a user