summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSamantaz Fox <coding@samantaz.fr>2022-02-04 04:09:07 +0100
committerSamantaz Fox <coding@samantaz.fr>2022-02-07 17:15:22 +0100
commitc04f45d5e36499e6faefd163e92c58fa1abaa7ae (patch)
treeeba321fecce9e0075ef0bcbaf39c7f237751bead /src
parentfb3615502258c71249c6d77aebe684234756b416 (diff)
downloadinvidious-c04f45d5e36499e6faefd163e92c58fa1abaa7ae.tar.gz
invidious-c04f45d5e36499e6faefd163e92c58fa1abaa7ae.tar.bz2
invidious-c04f45d5e36499e6faefd163e92c58fa1abaa7ae.zip
Move user struct to own file, under Invidious namespace
Diffstat (limited to 'src')
-rw-r--r--src/invidious.cr2
-rw-r--r--src/invidious/search.cr2
-rw-r--r--src/invidious/user/user.cr27
-rw-r--r--src/invidious/users.cr30
-rw-r--r--src/invidious/views/preferences.ecr2
-rw-r--r--src/invidious/views/template.ecr4
6 files changed, 34 insertions, 33 deletions
diff --git a/src/invidious.cr b/src/invidious.cr
index fc498dbf..1e78ef5d 100644
--- a/src/invidious.cr
+++ b/src/invidious.cr
@@ -548,7 +548,7 @@ add_handler AuthHandler.new
add_handler DenyFrame.new
add_context_storage_type(Array(String))
add_context_storage_type(Preferences)
-add_context_storage_type(User)
+add_context_storage_type(Invidious::User)
Kemal.config.logger = LOGGER
Kemal.config.host_binding = Kemal.config.host_binding != "0.0.0.0" ? Kemal.config.host_binding : CONFIG.host_binding
diff --git a/src/invidious/search.cr b/src/invidious/search.cr
index d8971e79..ae106bf6 100644
--- a/src/invidious/search.cr
+++ b/src/invidious/search.cr
@@ -176,7 +176,7 @@ end
def process_search_query(query, page, user, region)
if user
- user = user.as(User)
+ user = user.as(Invidious::User)
view_name = "subscriptions_#{sha256(user.email)}"
end
diff --git a/src/invidious/user/user.cr b/src/invidious/user/user.cr
new file mode 100644
index 00000000..a6d05fd1
--- /dev/null
+++ b/src/invidious/user/user.cr
@@ -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
diff --git a/src/invidious/users.cr b/src/invidious/users.cr
index 9810f8a2..b4995e95 100644
--- a/src/invidious/users.cr
+++ b/src/invidious/users.cr
@@ -3,32 +3,6 @@ require "crypto/bcrypt/password"
# 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" }
-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)
if email = Invidious::Database::SessionIDs.select_email(sid)
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))
- user = User.new({
+ user = Invidious::User.new({
updated: Time.utc,
notifications: [] of String,
subscriptions: channels,
@@ -102,7 +76,7 @@ def create_user(sid, email, password)
password = Crypto::Bcrypt::Password.create(password, cost: 10)
token = Base64.urlsafe_encode(Random::Secure.random_bytes(32))
- user = User.new({
+ user = Invidious::User.new({
updated: Time.utc,
notifications: [] of String,
subscriptions: [] of String,
diff --git a/src/invidious/views/preferences.ecr b/src/invidious/views/preferences.ecr
index 96904259..3606d140 100644
--- a/src/invidious/views/preferences.ecr
+++ b/src/invidious/views/preferences.ecr
@@ -252,7 +252,7 @@
<% 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>
<div class="pure-control-group">
diff --git a/src/invidious/views/template.ecr b/src/invidious/views/template.ecr
index 92df1272..bd908dd6 100644
--- a/src/invidious/views/template.ecr
+++ b/src/invidious/views/template.ecr
@@ -52,7 +52,7 @@
</div>
<div class="pure-u-1-4">
<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 %>
<span id="notification_count"><%= notification_count %></span> <i class="icon ion-ios-notifications"></i>
<% else %>
@@ -67,7 +67,7 @@
</div>
<% if env.get("preferences").as(Preferences).show_nick %>
<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>
<% end %>
<div class="pure-u-1-4">