From d9dce4a881dc1dcffe32d246746fc173d7cef159 Mon Sep 17 00:00:00 2001 From: torta Date: Sun, 5 Jun 2022 19:06:29 +0800 Subject: [PATCH 01/19] Fix Continue Reading not show missed reading chapter if the latest chapter mark as read --- src/library/title.cr | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/library/title.cr b/src/library/title.cr index e9873f2..e2a112c 100644 --- a/src/library/title.cr +++ b/src/library/title.cr @@ -632,6 +632,15 @@ class Title if last_read_entry && last_read_entry.finished? username last_read_entry = last_read_entry.next_entry username + # Get the last read entry in greedy + if last_read_entry.nil? + sorted_entries(username).each do |e| + unless e.finished? username + last_read_entry = e + break + end + end + end end last_read_entry From ea35faee91e82bc6d7e79881eaf8427eb7feb23f Mon Sep 17 00:00:00 2001 From: tr7zw Date: Tue, 7 Jun 2022 00:28:41 +0200 Subject: [PATCH 02/19] Add jxl support --- src/util/util.cr | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/util/util.cr b/src/util/util.cr index e08bd9d..cb53b46 100644 --- a/src/util/util.cr +++ b/src/util/util.cr @@ -11,6 +11,7 @@ SUPPORTED_IMG_TYPES = %w( image/avif image/gif image/svg+xml + image/jxl ) def random_str @@ -49,6 +50,7 @@ def register_mime_types # defiend by Crystal in `MIME.DEFAULT_TYPES` ".apng" => "image/apng", ".avif" => "image/avif", + ".jxl" => "image/jxl", }.each do |k, v| MIME.register k, v end From ae583cf2a9a2c12f099811c63c67886a651fe76d Mon Sep 17 00:00:00 2001 From: tr7zw Date: Tue, 7 Jun 2022 16:09:02 +0200 Subject: [PATCH 03/19] Workaround for "0 width/height" api responses This needs a more proper fix probably. --- public/js/reader.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/public/js/reader.js b/public/js/reader.js index a5d8e6b..11b3b49 100644 --- a/public/js/reader.js +++ b/public/js/reader.js @@ -29,14 +29,14 @@ const readerComponent = () => { return { id: i + 1, url: `${base_url}api/page/${tid}/${eid}/${i+1}`, - width: d.width, - height: d.height, + width: d.width == 0 ? "100%" : d.width, + height: d.height == 0 ? "100%" : d.height, }; }); - const avgRatio = this.items.reduce((acc, cur) => { + const avgRatio = dimensions.reduce((acc, cur) => { return acc + cur.height / cur.width - }, 0) / this.items.length; + }, 0) / dimensions.length; console.log(avgRatio); this.longPages = avgRatio > 2; From be46dd1f86afbf58b8cbe987445ab95ef8d6f7ea Mon Sep 17 00:00:00 2001 From: Chris Alexander Date: Wed, 15 Jun 2022 10:12:51 -0500 Subject: [PATCH 04/19] Allow config defaults to be sourced from ENV This allows the default config to source values from ENV variables if they are set. With this change we don't have to modify the docker CMD or edit the config.yml and then relaunch. --- spec/config_spec.cr | 21 +++++++++++++++++++-- src/config.cr | 46 ++++++++++++++++++++++----------------------- src/util/util.cr | 4 ++-- 3 files changed, 44 insertions(+), 27 deletions(-) diff --git a/spec/config_spec.cr b/spec/config_spec.cr index e2d5fca..5ea6f89 100644 --- a/spec/config_spec.cr +++ b/spec/config_spec.cr @@ -1,14 +1,31 @@ require "./spec_helper" describe Config do - it "creates config if it does not exist" do - with_default_config do |_, path| + it "creates default config if it does not exist" do + with_default_config do |config, path| File.exists?(path).should be_true + config.port.should eq 9000 end end it "correctly loads config" do config = Config.load "spec/asset/test-config.yml" config.port.should eq 3000 + config.base_url.should eq "/" + end + + it "correctly reads config defaults from ENV" do + ENV["LOG_LEVEL"] = "debug" + config = Config.load "spec/asset/test-config.yml" + config.log_level.should eq "debug" + config.base_url.should eq "/" + end + + it "correctly handles ENV truthiness" do + ENV["CACHE_ENABLED"] = "false" + config = Config.load "spec/asset/test-config.yml" + config.cache_enabled.should be_false + config.cache_log_enabled.should be_true + config.disable_login.should be_false end end diff --git a/src/config.cr b/src/config.cr index 807a74c..dd0fbda 100644 --- a/src/config.cr +++ b/src/config.cr @@ -4,28 +4,28 @@ class Config include YAML::Serializable @[YAML::Field(ignore: true)] - property path = "" - property host = "0.0.0.0" - property port : Int32 = 9000 - property base_url = "/" - property session_secret = "mango-session-secret" - property library_path = "~/mango/library" - property library_cache_path = "~/mango/library.yml.gz" - property db_path = "~/mango/mango.db" - property queue_db_path = "~/mango/queue.db" - property scan_interval_minutes : Int32 = 5 - property thumbnail_generation_interval_hours : Int32 = 24 - property log_level = "info" - property upload_path = "~/mango/uploads" - property plugin_path = "~/mango/plugins" - property download_timeout_seconds : Int32 = 30 - property cache_enabled = true - property cache_size_mbs = 50 - property cache_log_enabled = true - property disable_login = false - property default_username = "" - property auth_proxy_header_name = "" - property plugin_update_interval_hours : Int32 = 24 + property path : String = "" + property host : String = (ENV["LISTEN_HOST"]? || "0.0.0.0") + property port : Int32 = (ENV["LISTEN_PORT"]? || 9000).to_i + property base_url : String = (ENV["BASE_URL"]? || "/") + property session_secret : String = (ENV["SESSION_SECRET"]? || "mango-session-secret") + property library_path : String = (ENV["LIBRARY_PATH"]? || "~/mango/library") + property library_cache_path : String = (ENV["LIBRARY_CACHE_PATH"]? || "~/mango/library.yml.gz") + property db_path : String = (ENV["DB_PATH"]? || "~/mango/mango.db") + property queue_db_path : String = (ENV["QUEUE_DB_PATH"]? || "~/mango/queue.db") + property scan_interval_minutes : Int32 = (ENV["SCAN_INTERVAL"]? || 5).to_i + property thumbnail_generation_interval_hours : Int32 = (ENV["THUMBNAIL_INTERVAL"]? || 24).to_i + property log_level : String = (ENV["LOG_LEVEL"]? || "info") + property upload_path : String = (ENV["UPLOAD_PATH"]? || "~/mango/uploads") + property plugin_path : String = (ENV["PLUGIN_PATH"]? || "~/mango/plugins") + property download_timeout_seconds : Int32 = (ENV["DOWNLOAD_TIMEOUT"]? || 30).to_i + property cache_enabled : Bool = env_is_true?("CACHE_ENABLED", true) + property cache_size_mbs : Int32 = (ENV["CACHE_SIZE"]? || 50).to_i + property cache_log_enabled : Bool = env_is_true?("CACHE_LOG_ENABLED", true) + property disable_login : Bool = env_is_true?("DISABLE_LOGIN", false) + property default_username : String = (ENV["DEFAULT_USERNAME"]? || "") + property auth_proxy_header_name : String = (ENV["AUTH_PROXY_HEADER"]? || "") + property plugin_update_interval_hours : Int32 = (ENV["PLUGIN_UPDATE_INTERVAL"]? || 24).to_i @@singlet : Config? @@ -38,7 +38,7 @@ class Config end def self.load(path : String?) - path = "~/.config/mango/config.yml" if path.nil? + path = (ENV["CONFIG_PATH"]? || "~/.config/mango/config.yml") if path.nil? cfg_path = File.expand_path path, home: true if File.exists? cfg_path config = self.from_yaml File.read cfg_path diff --git a/src/util/util.cr b/src/util/util.cr index e08bd9d..ed3dc46 100644 --- a/src/util/util.cr +++ b/src/util/util.cr @@ -93,9 +93,9 @@ class String end end -def env_is_true?(key : String) : Bool +def env_is_true?(key : String, default : Bool = false) : Bool val = ENV[key.upcase]? || ENV[key.downcase]? - return false unless val + return default unless val val.downcase.in? "1", "true" end From bbc0c2cbb70407afb3bfaa2499c76d567b0f3276 Mon Sep 17 00:00:00 2001 From: Leeingnyo Date: Sat, 18 Jun 2022 17:43:26 +0900 Subject: [PATCH 05/19] Fix Dir.contents_signature to detect valid image files added --- src/util/signature.cr | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/util/signature.cr b/src/util/signature.cr index 8d2b961..bb16bed 100644 --- a/src/util/signature.cr +++ b/src/util/signature.cr @@ -64,11 +64,10 @@ class Dir path = File.join dirname, fn if File.directory? path signatures << Dir.contents_signature path, cache - signatures << fn if DirEntry.is_valid? path else # Only add its signature value to `signatures` when it is a # supported file - signatures << fn if ArchiveEntry.is_valid? fn + signatures << fn if ArchiveEntry.is_valid?(fn) || is_supported_image_file(fn) end Fiber.yield end From 17a9c8ecd3b9ee1c6ad1ccf30470e66708018e7b Mon Sep 17 00:00:00 2001 From: Leeingnyo Date: Sat, 18 Jun 2022 18:51:33 +0900 Subject: [PATCH 06/19] pass lint --- src/util/signature.cr | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/util/signature.cr b/src/util/signature.cr index bb16bed..74c8b8e 100644 --- a/src/util/signature.cr +++ b/src/util/signature.cr @@ -67,7 +67,9 @@ class Dir else # Only add its signature value to `signatures` when it is a # supported file - signatures << fn if ArchiveEntry.is_valid?(fn) || is_supported_image_file(fn) + if ArchiveEntry.is_valid?(fn) || is_supported_image_file(fn) + signatures << fn + end end Fiber.yield end From a639392ca05c0c19676222ae06d339479b978a72 Mon Sep 17 00:00:00 2001 From: Alex Ling Date: Sat, 18 Jun 2022 10:22:25 +0000 Subject: [PATCH 07/19] Update comment --- src/library/title.cr | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/library/title.cr b/src/library/title.cr index e2a112c..9c3ad78 100644 --- a/src/library/title.cr +++ b/src/library/title.cr @@ -632,8 +632,9 @@ class Title if last_read_entry && last_read_entry.finished? username last_read_entry = last_read_entry.next_entry username - # Get the last read entry in greedy if last_read_entry.nil? + # The last entry is finished. Return the first unfinished entry + # (if any) sorted_entries(username).each do |e| unless e.finished? username last_read_entry = e From fe440d82d49bab2ea793b41046f710fd4fd335ee Mon Sep 17 00:00:00 2001 From: Alex Ling Date: Sat, 18 Jun 2022 11:10:14 +0000 Subject: [PATCH 08/19] Fix linter issue --- src/util/util.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/util.cr b/src/util/util.cr index cb53b46..68e26c7 100644 --- a/src/util/util.cr +++ b/src/util/util.cr @@ -50,7 +50,7 @@ def register_mime_types # defiend by Crystal in `MIME.DEFAULT_TYPES` ".apng" => "image/apng", ".avif" => "image/avif", - ".jxl" => "image/jxl", + ".jxl" => "image/jxl", }.each do |k, v| MIME.register k, v end From 31df058f8135f8191c92583f7f06557c3f1ec4e1 Mon Sep 17 00:00:00 2001 From: Alex Ling Date: Sat, 18 Jun 2022 11:25:20 +0000 Subject: [PATCH 09/19] Comment about infinity average ratio --- public/js/reader.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/public/js/reader.js b/public/js/reader.js index 11b3b49..fa66b77 100644 --- a/public/js/reader.js +++ b/public/js/reader.js @@ -34,6 +34,8 @@ const readerComponent = () => { }; }); + // Note: for image types not supported by image_size.cr, the width and height will be 0, and so `avgRatio` will be `Infinity`. + // TODO: support more image types in image_size.cr const avgRatio = dimensions.reduce((acc, cur) => { return acc + cur.height / cur.width }, 0) / dimensions.length; From 2e91028ead3ade765a75ac1fe76781c9a82d596d Mon Sep 17 00:00:00 2001 From: Chris Alexander Date: Wed, 15 Jun 2022 10:12:51 -0500 Subject: [PATCH 10/19] Allow config defaults to be sourced from ENV This allows the default config to source values from ENV variables if they are set. With this change we don't have to modify the docker CMD or edit the config.yml and then relaunch. --- spec/config_spec.cr | 21 ++++++++++++++++-- src/config.cr | 52 +++++++++++++++++++++++++-------------------- src/util/util.cr | 4 ++-- 3 files changed, 50 insertions(+), 27 deletions(-) diff --git a/spec/config_spec.cr b/spec/config_spec.cr index e2d5fca..5ea6f89 100644 --- a/spec/config_spec.cr +++ b/spec/config_spec.cr @@ -1,14 +1,31 @@ require "./spec_helper" describe Config do - it "creates config if it does not exist" do - with_default_config do |_, path| + it "creates default config if it does not exist" do + with_default_config do |config, path| File.exists?(path).should be_true + config.port.should eq 9000 end end it "correctly loads config" do config = Config.load "spec/asset/test-config.yml" config.port.should eq 3000 + config.base_url.should eq "/" + end + + it "correctly reads config defaults from ENV" do + ENV["LOG_LEVEL"] = "debug" + config = Config.load "spec/asset/test-config.yml" + config.log_level.should eq "debug" + config.base_url.should eq "/" + end + + it "correctly handles ENV truthiness" do + ENV["CACHE_ENABLED"] = "false" + config = Config.load "spec/asset/test-config.yml" + config.cache_enabled.should be_false + config.cache_log_enabled.should be_true + config.disable_login.should be_false end end diff --git a/src/config.cr b/src/config.cr index 807a74c..f4a2cf3 100644 --- a/src/config.cr +++ b/src/config.cr @@ -4,28 +4,34 @@ class Config include YAML::Serializable @[YAML::Field(ignore: true)] - property path = "" - property host = "0.0.0.0" - property port : Int32 = 9000 - property base_url = "/" - property session_secret = "mango-session-secret" - property library_path = "~/mango/library" - property library_cache_path = "~/mango/library.yml.gz" - property db_path = "~/mango/mango.db" - property queue_db_path = "~/mango/queue.db" - property scan_interval_minutes : Int32 = 5 - property thumbnail_generation_interval_hours : Int32 = 24 - property log_level = "info" - property upload_path = "~/mango/uploads" - property plugin_path = "~/mango/plugins" - property download_timeout_seconds : Int32 = 30 - property cache_enabled = true - property cache_size_mbs = 50 - property cache_log_enabled = true - property disable_login = false - property default_username = "" - property auth_proxy_header_name = "" - property plugin_update_interval_hours : Int32 = 24 + property path : String = "" + property host : String = (ENV["LISTEN_HOST"]? || "0.0.0.0") + property port : Int32 = (ENV["LISTEN_PORT"]? || 9000).to_i + property base_url : String = (ENV["BASE_URL"]? || "/") + property session_secret : String = \ + (ENV["SESSION_SECRET"]? || "mango-session-secret") + property library_path : String = (ENV["LIBRARY_PATH"]? || "~/mango/library") + property library_cache_path : String = \ + (ENV["LIBRARY_CACHE_PATH"]? || "~/mango/library.yml.gz") + property db_path : String = (ENV["DB_PATH"]? || "~/mango/mango.db") + property queue_db_path : String = \ + (ENV["QUEUE_DB_PATH"]? || "~/mango/queue.db") + property scan_interval_minutes : Int32 = (ENV["SCAN_INTERVAL"]? || 5).to_i + property thumbnail_generation_interval_hours : Int32 = \ + (ENV["THUMBNAIL_INTERVAL"]? || 24).to_i + property log_level : String = (ENV["LOG_LEVEL"]? || "info") + property upload_path : String = (ENV["UPLOAD_PATH"]? || "~/mango/uploads") + property plugin_path : String = (ENV["PLUGIN_PATH"]? || "~/mango/plugins") + property download_timeout_seconds : Int32 = \ + (ENV["DOWNLOAD_TIMEOUT"]? || 30).to_i + property cache_enabled : Bool = env_is_true?("CACHE_ENABLED", true) + property cache_size_mbs : Int32 = (ENV["CACHE_SIZE"]? || 50).to_i + property cache_log_enabled : Bool = env_is_true?("CACHE_LOG_ENABLED", true) + property disable_login : Bool = env_is_true?("DISABLE_LOGIN", false) + property default_username : String = (ENV["DEFAULT_USERNAME"]? || "") + property auth_proxy_header_name : String = (ENV["AUTH_PROXY_HEADER"]? || "") + property plugin_update_interval_hours : Int32 = \ + (ENV["PLUGIN_UPDATE_INTERVAL"]? || 24).to_i @@singlet : Config? @@ -38,7 +44,7 @@ class Config end def self.load(path : String?) - path = "~/.config/mango/config.yml" if path.nil? + path = (ENV["CONFIG_PATH"]? || "~/.config/mango/config.yml") if path.nil? cfg_path = File.expand_path path, home: true if File.exists? cfg_path config = self.from_yaml File.read cfg_path diff --git a/src/util/util.cr b/src/util/util.cr index 68e26c7..ce658aa 100644 --- a/src/util/util.cr +++ b/src/util/util.cr @@ -95,9 +95,9 @@ class String end end -def env_is_true?(key : String) : Bool +def env_is_true?(key : String, default : Bool = false) : Bool val = ENV[key.upcase]? || ENV[key.downcase]? - return false unless val + return default unless val val.downcase.in? "1", "true" end From f3eb62a2714326489b6773c4ea0a0be07a767dbe Mon Sep 17 00:00:00 2001 From: Chris Alexander Date: Mon, 27 Jun 2022 09:19:12 -0500 Subject: [PATCH 11/19] Disable line length warnings --- src/config.cr | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/config.cr b/src/config.cr index f4a2cf3..867b8ab 100644 --- a/src/config.cr +++ b/src/config.cr @@ -8,30 +8,30 @@ class Config property host : String = (ENV["LISTEN_HOST"]? || "0.0.0.0") property port : Int32 = (ENV["LISTEN_PORT"]? || 9000).to_i property base_url : String = (ENV["BASE_URL"]? || "/") - property session_secret : String = \ - (ENV["SESSION_SECRET"]? || "mango-session-secret") + # ameba:disable Layout/LineLength + property session_secret : String = (ENV["SESSION_SECRET"]? || "mango-session-secret") property library_path : String = (ENV["LIBRARY_PATH"]? || "~/mango/library") - property library_cache_path : String = \ - (ENV["LIBRARY_CACHE_PATH"]? || "~/mango/library.yml.gz") + # ameba:disable Layout/LineLength + property library_cache_path : String = (ENV["LIBRARY_CACHE_PATH"]? || "~/mango/library.yml.gz") property db_path : String = (ENV["DB_PATH"]? || "~/mango/mango.db") - property queue_db_path : String = \ - (ENV["QUEUE_DB_PATH"]? || "~/mango/queue.db") + # ameba:disable Layout/LineLength + property queue_db_path : String = (ENV["QUEUE_DB_PATH"]? || "~/mango/queue.db") property scan_interval_minutes : Int32 = (ENV["SCAN_INTERVAL"]? || 5).to_i - property thumbnail_generation_interval_hours : Int32 = \ - (ENV["THUMBNAIL_INTERVAL"]? || 24).to_i + # ameba:disable Layout/LineLength + property thumbnail_generation_interval_hours : Int32 = (ENV["THUMBNAIL_INTERVAL"]? || 24).to_i property log_level : String = (ENV["LOG_LEVEL"]? || "info") property upload_path : String = (ENV["UPLOAD_PATH"]? || "~/mango/uploads") property plugin_path : String = (ENV["PLUGIN_PATH"]? || "~/mango/plugins") - property download_timeout_seconds : Int32 = \ - (ENV["DOWNLOAD_TIMEOUT"]? || 30).to_i + # ameba:disable Layout/LineLength + property download_timeout_seconds : Int32 = (ENV["DOWNLOAD_TIMEOUT"]? || 30).to_i property cache_enabled : Bool = env_is_true?("CACHE_ENABLED", true) property cache_size_mbs : Int32 = (ENV["CACHE_SIZE"]? || 50).to_i property cache_log_enabled : Bool = env_is_true?("CACHE_LOG_ENABLED", true) property disable_login : Bool = env_is_true?("DISABLE_LOGIN", false) property default_username : String = (ENV["DEFAULT_USERNAME"]? || "") property auth_proxy_header_name : String = (ENV["AUTH_PROXY_HEADER"]? || "") - property plugin_update_interval_hours : Int32 = \ - (ENV["PLUGIN_UPDATE_INTERVAL"]? || 24).to_i + # ameba:disable Layout/LineLength + property plugin_update_interval_hours : Int32 = (ENV["PLUGIN_UPDATE_INTERVAL"]? || 24).to_i @@singlet : Config? From f2d6d28a72cbc0c932623a643ec541ba14e94287 Mon Sep 17 00:00:00 2001 From: Alex Ling Date: Sun, 3 Jul 2022 07:24:33 +0000 Subject: [PATCH 12/19] Define properties with macro --- src/config.cr | 68 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 27 deletions(-) diff --git a/src/config.cr b/src/config.cr index 867b8ab..2384431 100644 --- a/src/config.cr +++ b/src/config.cr @@ -1,37 +1,51 @@ require "yaml" class Config + private OPTIONS = { + "host" => "0.0.0.0", + "port" => 9000, + "base_url" => "/", + "session_secret" => "mango-session-secret", + "library_path" => "~/mango/library", + "library_cache_path" => "~/mango/library.yml.gz", + "db_path" => "~/mango.db", + "queue_db_path" => "~/mango/queue.db", + "scan_interval_minutes" => 5, + "thumbnail_generation_interval_hours" => 24, + "log_level" => "info", + "upload_path" => "~/mango/uploads", + "plugin_path" => "~/mango/plugins", + "download_timeout_seconds" => 30, + "cache_enabled" => true, + "cache_size_mbs" => 50, + "cache_log_enabled" => true, + "disable_login" => false, + "default_username" => "", + "auth_proxy_header_name" => "", + "plugin_update_interval_hours" => 24, + } + include YAML::Serializable @[YAML::Field(ignore: true)] property path : String = "" - property host : String = (ENV["LISTEN_HOST"]? || "0.0.0.0") - property port : Int32 = (ENV["LISTEN_PORT"]? || 9000).to_i - property base_url : String = (ENV["BASE_URL"]? || "/") - # ameba:disable Layout/LineLength - property session_secret : String = (ENV["SESSION_SECRET"]? || "mango-session-secret") - property library_path : String = (ENV["LIBRARY_PATH"]? || "~/mango/library") - # ameba:disable Layout/LineLength - property library_cache_path : String = (ENV["LIBRARY_CACHE_PATH"]? || "~/mango/library.yml.gz") - property db_path : String = (ENV["DB_PATH"]? || "~/mango/mango.db") - # ameba:disable Layout/LineLength - property queue_db_path : String = (ENV["QUEUE_DB_PATH"]? || "~/mango/queue.db") - property scan_interval_minutes : Int32 = (ENV["SCAN_INTERVAL"]? || 5).to_i - # ameba:disable Layout/LineLength - property thumbnail_generation_interval_hours : Int32 = (ENV["THUMBNAIL_INTERVAL"]? || 24).to_i - property log_level : String = (ENV["LOG_LEVEL"]? || "info") - property upload_path : String = (ENV["UPLOAD_PATH"]? || "~/mango/uploads") - property plugin_path : String = (ENV["PLUGIN_PATH"]? || "~/mango/plugins") - # ameba:disable Layout/LineLength - property download_timeout_seconds : Int32 = (ENV["DOWNLOAD_TIMEOUT"]? || 30).to_i - property cache_enabled : Bool = env_is_true?("CACHE_ENABLED", true) - property cache_size_mbs : Int32 = (ENV["CACHE_SIZE"]? || 50).to_i - property cache_log_enabled : Bool = env_is_true?("CACHE_LOG_ENABLED", true) - property disable_login : Bool = env_is_true?("DISABLE_LOGIN", false) - property default_username : String = (ENV["DEFAULT_USERNAME"]? || "") - property auth_proxy_header_name : String = (ENV["AUTH_PROXY_HEADER"]? || "") - # ameba:disable Layout/LineLength - property plugin_update_interval_hours : Int32 = (ENV["PLUGIN_UPDATE_INTERVAL"]? || 24).to_i + + # Go through the options constant above and define them as properties. + # Allow setting the default values through environment variables. + # Overall precedence: config file > environment variable > default value + {% begin %} + {% for k, v in OPTIONS %} + {% if v.is_a? StringLiteral %} + property {{k.id}} : String = ENV[{{k.upcase}}]? || {{ v }} + {% elsif v.is_a? NumberLiteral %} + property {{k.id}} : Int32 = (ENV[{{k.upcase}}]? || {{ v.id }}).to_i + {% elsif v.is_a? BoolLiteral %} + property {{k.id}} : Bool = env_is_true? {{ k.upcase }}, {{ v.id }} + {% else %} + raise "Unknown type in config option: {{ v.class_name.id }}" + {% end %} + {% end %} + {% end %} @@singlet : Config? From 405b958deb4428b2aca0568c7ecf00225fbd0de8 Mon Sep 17 00:00:00 2001 From: Hiers Date: Tue, 5 Jul 2022 22:01:21 +0100 Subject: [PATCH 13/19] First draft of image fit. --- public/js/reader.js | 26 ++++++++++++++++++++++++++ src/views/reader.html.ecr | 21 ++++++++++++++++----- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/public/js/reader.js b/public/js/reader.js index fa66b77..6cacf78 100644 --- a/public/js/reader.js +++ b/public/js/reader.js @@ -14,6 +14,7 @@ const readerComponent = () => { margin: 30, preloadLookahead: 3, enableRightToLeft: false, + fitType: 'vert', /** * Initialize the component by fetching the page dimensions @@ -65,6 +66,10 @@ const readerComponent = () => { this.preloadImage(this.items[idx - 1].url); } + const savedFitType = localStorage.getItem('fitType'); + if(savedFitType){ + this.fitType = savedFitType; + } const savedFlipAnimation = localStorage.getItem('enableFlipAnimation'); this.enableFlipAnimation = savedFlipAnimation === null || savedFlipAnimation === 'true'; @@ -301,6 +306,21 @@ const readerComponent = () => { }); }); }, + /** + * Changes how the view should fit to the screen or if it should use the image's real size + * + * @param {string} fitType - ver, horz and real for fitting to height, width, + * and showing real size, respectively + */ + setFit(fitType){ + if (fitType === 'vert'){ + document.styleSheets[0].rules[21].style.maxWidth = '100%'; + } else if(fitType === 'horz'){ + document.styleSheets[0].rules[21].style.maxWidth = '100%'; + } else if (fitType === 'real'){ + document.styleSheets[0].rules[21].style.maxWidth = ''; + } + }, /** * Marks progress as 100% and jumps to the next entry * @@ -335,6 +355,12 @@ const readerComponent = () => { this.toPage(this.selectedIndex); }, + fitChanged(){ + this.fitType = $('#fit-select').val(); + this.setFit(this.fitType); + localStorage.setItem('fitType', this.fitType); + }, + preloadLookaheadChanged() { localStorage.setItem('preloadLookahead', this.preloadLookahead); }, diff --git a/src/views/reader.html.ecr b/src/views/reader.html.ecr index 19e2b19..6e4fc8a 100644 --- a/src/views/reader.html.ecr +++ b/src/views/reader.html.ecr @@ -40,18 +40,18 @@ <%- end -%> -
+
@@ -94,6 +94,17 @@
+
+ +
+ +
+
+
From db5e99b3f0a202029c1862da6013eaf356102d0e Mon Sep 17 00:00:00 2001 From: Hiers Date: Tue, 5 Jul 2022 22:24:31 +0100 Subject: [PATCH 14/19] Fix in reader.html.ecr. --- src/views/reader.html.ecr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/reader.html.ecr b/src/views/reader.html.ecr index 6e4fc8a..dacd222 100644 --- a/src/views/reader.html.ecr +++ b/src/views/reader.html.ecr @@ -48,7 +48,7 @@ 'uk-animation-slide-right': flipAnimation === 'right' }" :data-src="curItem.url" :width="curItem.width" :height="curItem.height" :id="curItem.id" @click="clickImage($event)" :style="` width:${fitType === 'horz' ? '100vw' : 'auto'}; - height:${mode === 'vert' ? '100vh' : 'auto'}; + height:${fitType === 'vert' ? '100vh' : 'auto'}; margin-bottom:0; max-width:${fitType === 'horz' ? '100%' : ''}; max-height:${fitType === 'vert' ? '100%' : ''}; From 6ddbe8d43657867bf663d209fe1d8e027f25c6f1 Mon Sep 17 00:00:00 2001 From: Hiers Date: Thu, 7 Jul 2022 08:55:54 +0100 Subject: [PATCH 15/19] Changed setFit function to not have redundant ifs and a better comment explaining what it does. --- public/js/reader.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/public/js/reader.js b/public/js/reader.js index 6cacf78..df92b4f 100644 --- a/public/js/reader.js +++ b/public/js/reader.js @@ -307,18 +307,16 @@ const readerComponent = () => { }); }, /** - * Changes how the view should fit to the screen or if it should use the image's real size + * Sets the image to not be restricted to the size of its container if it's not being scaled * * @param {string} fitType - ver, horz and real for fitting to height, width, * and showing real size, respectively */ setFit(fitType){ - if (fitType === 'vert'){ - document.styleSheets[0].rules[21].style.maxWidth = '100%'; - } else if(fitType === 'horz'){ - document.styleSheets[0].rules[21].style.maxWidth = '100%'; - } else if (fitType === 'real'){ + if (fitType === 'real'){ document.styleSheets[0].rules[21].style.maxWidth = ''; + } else { + document.styleSheets[0].rules[21].style.maxWidth = '100%'; } }, /** From 624283643ccc19551db3c19cbb1c9bbedcb8b377 Mon Sep 17 00:00:00 2001 From: Hiers Date: Wed, 13 Jul 2022 14:20:43 +0100 Subject: [PATCH 16/19] Fixed right flip panel not being all the way on the right; changed real image size option to not be hard coded. --- public/js/reader.js | 17 ++--------------- src/views/reader.html.ecr | 8 ++++---- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/public/js/reader.js b/public/js/reader.js index df92b4f..63cef7f 100644 --- a/public/js/reader.js +++ b/public/js/reader.js @@ -67,8 +67,9 @@ const readerComponent = () => { } const savedFitType = localStorage.getItem('fitType'); - if(savedFitType){ + if (savedFitType) { this.fitType = savedFitType; + $('#fit-select').val(savedFitType); } const savedFlipAnimation = localStorage.getItem('enableFlipAnimation'); this.enableFlipAnimation = savedFlipAnimation === null || savedFlipAnimation === 'true'; @@ -306,19 +307,6 @@ const readerComponent = () => { }); }); }, - /** - * Sets the image to not be restricted to the size of its container if it's not being scaled - * - * @param {string} fitType - ver, horz and real for fitting to height, width, - * and showing real size, respectively - */ - setFit(fitType){ - if (fitType === 'real'){ - document.styleSheets[0].rules[21].style.maxWidth = ''; - } else { - document.styleSheets[0].rules[21].style.maxWidth = '100%'; - } - }, /** * Marks progress as 100% and jumps to the next entry * @@ -355,7 +343,6 @@ const readerComponent = () => { fitChanged(){ this.fitType = $('#fit-select').val(); - this.setFit(this.fitType); localStorage.setItem('fitType', this.fitType); }, diff --git a/src/views/reader.html.ecr b/src/views/reader.html.ecr index dacd222..f1e7236 100644 --- a/src/views/reader.html.ecr +++ b/src/views/reader.html.ecr @@ -19,7 +19,7 @@
+ :class="{'uk-container': true, 'uk-container-small': mode === 'continuous', 'uk-container-expand': mode !== 'continuous'}" style="width: fit-content;">