diff --git a/src/invidious/users.cr b/src/invidious/users.cr index e9682992..47a4197f 100644 --- a/src/invidious/users.cr +++ b/src/invidious/users.cr @@ -51,7 +51,7 @@ struct Preferences @[YAML::Field(converter: Preferences::BoolToString)] property dark_mode : String = CONFIG.default_user_preferences.dark_mode - @[JSON::Field(converter: Preferences::ClampInt)] + @[JSON::Field(converter: Preferences::ClampFeedCols)] property feed_cols : Int32 = CONFIG.default_user_preferences.feed_cols property latest_only : Bool = CONFIG.default_user_preferences.latest_only property listen : Bool = CONFIG.default_user_preferences.listen @@ -147,6 +147,36 @@ struct Preferences end end + module ClampFeedCols + def self.to_json(value : Int32, json : JSON::Builder) + case value.clamp(2, 8) + when 7 + # Pure CSS does not have pure-g-*-1-7 + json.number 8 + else + json.number value.clamp(2, 8) + end + end + + def self.from_json(value : JSON::PullParser) : Int32 + value.read_int.clamp(2, 8).to_i32 + end + + def self.to_yaml(value : Int32, yaml : YAML::Nodes::Builder) + case value.clamp(2, 8) + when 7 + # Pure CSS does not have pure-g-*-1-7 + yaml.scalar 8 + else + yaml.scalar value.clamp(2, 8) + end + end + + def self.from_yaml(ctx : YAML::ParseContext, node : YAML::Nodes::Node) : Int32 + node.value.clamp(2, 9) + end + end + module FamilyConverter def self.to_yaml(value : Socket::Family, yaml : YAML::Nodes::Builder) case value diff --git a/src/invidious/views/preferences.ecr b/src/invidious/views/preferences.ecr index 00f27413..e1219482 100644 --- a/src/invidious/views/preferences.ecr +++ b/src/invidious/views/preferences.ecr @@ -174,7 +174,7 @@