From a6292d956d9189866aeeed73182b3780d76337a1 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Mon, 16 Jul 2018 19:31:49 -0500 Subject: [PATCH] Add option to change max_results --- src/invidious.cr | 21 +++++++++++++-------- src/invidious/helpers.cr | 26 ++++++++++++++------------ src/invidious/views/preferences.ecr | 6 ++++++ 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index 7254d9f5..1428e95d 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -683,7 +683,6 @@ get "/preferences" do |env| referer ||= "/preferences" if referer.size > 64 - puts "nope" referer = "/preferences" end @@ -725,13 +724,17 @@ post "/preferences" do |env| dark_mode ||= "off" dark_mode = dark_mode == "on" + max_results = env.params.body["max_results"]?.try &.as(String).to_i + max_results ||= 40 + preferences = { - "video_loop" => video_loop, - "autoplay" => autoplay, - "speed" => speed, - "quality" => quality, - "volume" => volume, - "dark_mode" => dark_mode, + "video_loop" => video_loop, + "autoplay" => autoplay, + "speed" => speed, + "quality" => quality, + "volume" => volume, + "dark_mode" => dark_mode, + "max_results" => max_results, }.to_json PG_DB.exec("UPDATE users SET preferences = $1 WHERE email = $2", preferences, user.email) @@ -747,7 +750,9 @@ get "/feed/subscriptions" do |env| if user user = user.as(User) - max_results = env.params.query["maxResults"]?.try &.to_i || 40 + max_results = user.preferences.max_results + max_results ||= env.params.query["maxResults"]?.try &.to_i + max_results ||= 40 page = env.params.query["page"]?.try &.to_i page ||= 1 diff --git a/src/invidious/helpers.cr b/src/invidious/helpers.cr index 81c025a3..36e48adb 100644 --- a/src/invidious/helpers.cr +++ b/src/invidious/helpers.cr @@ -18,12 +18,13 @@ macro rendered(filename) end DEFAULT_USER_PREFERENCES = Preferences.from_json({ - "video_loop" => false, - "autoplay" => false, - "speed" => 1.0, - "quality" => "hd720", - "volume" => 100, - "dark_mode" => false, + "video_loop" => false, + "autoplay" => false, + "speed" => 1.0, + "quality" => "hd720", + "volume" => 100, + "dark_mode" => false, + "max_results" => 40, }.to_json) class Config @@ -136,12 +137,13 @@ end class Preferences JSON.mapping({ - video_loop: Bool, - autoplay: Bool, - speed: Float32, - quality: String, - volume: Int32, - dark_mode: Bool, + video_loop: Bool, + autoplay: Bool, + speed: Float32, + quality: String, + volume: Int32, + dark_mode: Bool, + max_results: Int32, }) end diff --git a/src/invidious/views/preferences.ecr b/src/invidious/views/preferences.ecr index c38b14d7..10e58a4b 100644 --- a/src/invidious/views/preferences.ecr +++ b/src/invidious/views/preferences.ecr @@ -52,6 +52,12 @@ function update_value(element) { checked<% end %>> + Subscription preferences +
+ + +
+