mirror of
https://github.com/iv-org/invidious.git
synced 2024-11-22 13:37:24 +00:00
Move TimeSpanConverter with another Converters
Follow indications : https://github.com/iv-org/invidious/pull/2915#discussion_r811373953
This commit is contained in:
parent
5d2f2690e2
commit
f109d812a1
@ -59,7 +59,7 @@ class Config
|
|||||||
# Number of threads to use for crawling videos from channels (for updating subscriptions)
|
# Number of threads to use for crawling videos from channels (for updating subscriptions)
|
||||||
property channel_threads : Int32 = 1
|
property channel_threads : Int32 = 1
|
||||||
# Time between two jobs for crawling videos from channels
|
# Time between two jobs for crawling videos from channels
|
||||||
@[YAML::Field(converter: TimeSpanConverter)]
|
@[YAML::Field(converter: Preferences::TimeSpanConverter)]
|
||||||
property channel_refresh_interval : Time::Span = 30.minutes
|
property channel_refresh_interval : Time::Span = 30.minutes
|
||||||
# Number of threads to use for updating feeds
|
# Number of threads to use for updating feeds
|
||||||
property feed_threads : Int32 = 1
|
property feed_threads : Int32 = 1
|
||||||
|
@ -18,20 +18,6 @@ def elapsed_text(elapsed)
|
|||||||
"#{(millis * 1000).round(2)}µs"
|
"#{(millis * 1000).round(2)}µs"
|
||||||
end
|
end
|
||||||
|
|
||||||
module TimeSpanConverter
|
|
||||||
def self.to_yaml(value : Time::Span, yaml : YAML::Nodes::Builder)
|
|
||||||
return yaml.scalar recode_length_seconds(value.total_seconds.to_i32)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.from_yaml(ctx : YAML::ParseContext, node : YAML::Nodes::Node) : Time::Span
|
|
||||||
if node.is_a?(YAML::Nodes::Scalar)
|
|
||||||
return decode_time_span(node.value)
|
|
||||||
else
|
|
||||||
node.raise "Expected scalar, not #{node.class}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def decode_time_span(string : String) : Time::Span
|
def decode_time_span(string : String) : Time::Span
|
||||||
time_span = string.gsub(/[^0-9:]/, "")
|
time_span = string.gsub(/[^0-9:]/, "")
|
||||||
return Time::Span.new(seconds: 0) if time_span.empty?
|
return Time::Span.new(seconds: 0) if time_span.empty?
|
||||||
|
@ -256,4 +256,18 @@ struct Preferences
|
|||||||
cookies
|
cookies
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module TimeSpanConverter
|
||||||
|
def self.to_yaml(value : Time::Span, yaml : YAML::Nodes::Builder)
|
||||||
|
return yaml.scalar recode_length_seconds(value.total_seconds.to_i32)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.from_yaml(ctx : YAML::ParseContext, node : YAML::Nodes::Node) : Time::Span
|
||||||
|
if node.is_a?(YAML::Nodes::Scalar)
|
||||||
|
return decode_time_span(node.value)
|
||||||
|
else
|
||||||
|
node.raise "Expected scalar, not #{node.class}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user