summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamantaz Fox <coding@samantaz.fr>2021-10-07 13:53:55 +0200
committerSamantaz Fox <coding@samantaz.fr>2021-10-28 17:48:07 +0200
commit60fa552469b5c1d39fd78a3e6a7f5aa133bd3fc7 (patch)
treef18007478bb71709ef6ba9561a218684dd3347e4
parent2b81a82620cee3c1dac3c9b314f37dc2f8ac3086 (diff)
downloadinvidious-60fa552469b5c1d39fd78a3e6a7f5aa133bd3fc7.tar.gz
invidious-60fa552469b5c1d39fd78a3e6a7f5aa133bd3fc7.tar.bz2
invidious-60fa552469b5c1d39fd78a3e6a7f5aa133bd3fc7.zip
Fix an infinite recursion caused by #2228
Changes in the aforementioned PR lead to change the behavior of some old code. The data type of the parameters aren't explicit enough, which makes the compiler use the wrong method because of type infering.
-rw-r--r--src/invidious/helpers/serialized_yt_data.cr66
1 files changed, 31 insertions, 35 deletions
diff --git a/src/invidious/helpers/serialized_yt_data.cr b/src/invidious/helpers/serialized_yt_data.cr
index 1ba3f20e..0cac7c49 100644
--- a/src/invidious/helpers/serialized_yt_data.cr
+++ b/src/invidious/helpers/serialized_yt_data.cr
@@ -58,17 +58,13 @@ struct SearchVideo
end
end
- def to_xml(auto_generated, query_params, xml : XML::Builder | Nil = nil)
- if xml
- to_xml(HOST_URL, auto_generated, query_params, xml)
- else
- XML.build do |xml|
- to_xml(HOST_URL, auto_generated, query_params, xml)
- end
+ def to_xml(auto_generated, query_params, _xml : Nil)
+ XML.build do |xml|
+ to_xml(auto_generated, query_params, xml)
end
end
- def to_json(locale : Hash(String, JSON::Any), json : JSON::Builder)
+ def to_json(locale : Hash(String, JSON::Any) | Nil, json : JSON::Builder)
json.object do
json.field "type", "video"
json.field "title", self.title
@@ -99,16 +95,16 @@ struct SearchVideo
end
end
- def to_json(locale, json : JSON::Builder | Nil = nil)
- if json
+ def to_json(locale : Hash(String, JSON::Any) | Nil, _json : Nil = nil)
+ JSON.build do |json|
to_json(locale, json)
- else
- JSON.build do |json|
- to_json(locale, json)
- end
end
end
+ def to_json(json : JSON::Builder)
+ to_json(nil, json)
+ end
+
def is_upcoming
premiere_timestamp ? true : false
end
@@ -133,7 +129,7 @@ struct SearchPlaylist
property videos : Array(SearchPlaylistVideo)
property thumbnail : String?
- def to_json(locale, json : JSON::Builder)
+ def to_json(locale : Hash(String, JSON::Any) | Nil, json : JSON::Builder)
json.object do
json.field "type", "playlist"
json.field "title", self.title
@@ -163,15 +159,15 @@ struct SearchPlaylist
end
end
- def to_json(locale, json : JSON::Builder | Nil = nil)
- if json
+ def to_json(locale : Hash(String, JSON::Any) | Nil, _json : Nil = nil)
+ JSON.build do |json|
to_json(locale, json)
- else
- JSON.build do |json|
- to_json(locale, json)
- end
end
end
+
+ def to_json(json : JSON::Builder)
+ to_json(nil, json)
+ end
end
struct SearchChannel
@@ -185,7 +181,7 @@ struct SearchChannel
property description_html : String
property auto_generated : Bool
- def to_json(locale, json : JSON::Builder)
+ def to_json(locale : Hash(String, JSON::Any) | Nil, json : JSON::Builder)
json.object do
json.field "type", "channel"
json.field "author", self.author
@@ -215,15 +211,15 @@ struct SearchChannel
end
end
- def to_json(locale, json : JSON::Builder | Nil = nil)
- if json
+ def to_json(locale, _json : Nil = nil)
+ JSON.build do |json|
to_json(locale, json)
- else
- JSON.build do |json|
- to_json(locale, json)
- end
end
end
+
+ def to_json(json : JSON::Builder)
+ to_json(nil, json)
+ end
end
class Category
@@ -235,7 +231,7 @@ class Category
property description_html : String
property badges : Array(Tuple(String, String))?
- def to_json(locale, json : JSON::Builder)
+ def to_json(locale : Hash(String, JSON::Any) | Nil, json : JSON::Builder)
json.object do
json.field "type", "category"
json.field "title", self.title
@@ -249,15 +245,15 @@ class Category
end
end
- def to_json(locale, json : JSON::Builder | Nil = nil)
- if json
+ def to_json(locale : Hash(String, JSON::Any) | Nil, _json : Nil = nil)
+ JSON.build do |json|
to_json(locale, json)
- else
- JSON.build do |json|
- to_json(locale, json)
- end
end
end
+
+ def to_json(json : JSON::Builder)
+ to_json(nil, json)
+ end
end
alias SearchItem = SearchVideo | SearchChannel | SearchPlaylist | Category