Invidious is an alternative front-end to YouTube
Fix warnings in Crystal 0.29
Omar Roth2febc268f784
diff --git a/shard.yml b/shard.ymlindex 0d54a2f9..0e33c2fa 100644--- a/shard.yml+++ b/shard.yml@@ -13,9 +13,10 @@ dependencies:github: kemalcr/kemalpg:github: will/crystal-pg+ branch: cafe69esqlite3:github: crystal-lang/crystal-sqlite3-crystal: 0.28.0+crystal: 0.29.0license: AGPLv3diff --git a/src/invidious.cr b/src/invidious.crindex 83bdc5be..573855c7 100644--- a/src/invidious.cr+++ b/src/invidious.cr@@ -1089,7 +1089,7 @@ post "/login" do |env|PG_DB.exec("UPDATE users SET preferences = $1 WHERE email = $2", preferences.to_json, user.email)cookie = env.request.cookies["PREFS"]- cookie.expires = Time.new(1990, 1, 1)+ cookie.expires = Time.utc(1990, 1, 1)env.response.cookies << cookieend@@ -1117,7 +1117,7 @@ post "/login" do |env|next templated "error"end- if Crypto::Bcrypt::Password.new(user.password.not_nil!) == password.byte_slice(0, 55)+ if Crypto::Bcrypt::Password.new(user.password.not_nil!).verify(password.byte_slice(0, 55))sid = Base64.urlsafe_encode(Random::Secure.random_bytes(32))PG_DB.exec("INSERT INTO session_ids VALUES ($1, $2, $3)", sid, email, Time.utc)@@ -1142,7 +1142,7 @@ post "/login" do |env|# Since this user has already registered, we don't want to overwrite their preferencesif env.request.cookies["PREFS"]?cookie = env.request.cookies["PREFS"]- cookie.expires = Time.new(1990, 1, 1)+ cookie.expires = Time.utc(1990, 1, 1)env.response.cookies << cookieendelse@@ -1260,7 +1260,7 @@ post "/login" do |env|PG_DB.exec("UPDATE users SET preferences = $1 WHERE email = $2", preferences.to_json, user.email)cookie = env.request.cookies["PREFS"]- cookie.expires = Time.new(1990, 1, 1)+ cookie.expires = Time.utc(1990, 1, 1)env.response.cookies << cookieendend@@ -1294,7 +1294,7 @@ post "/signout" do |env|PG_DB.exec("DELETE FROM session_ids * WHERE id = $1", sid)env.request.cookies.each do |cookie|- cookie.expires = Time.new(1990, 1, 1)+ cookie.expires = Time.utc(1990, 1, 1)env.response.cookies << cookieendend@@ -2064,7 +2064,7 @@ post "/change_password" do |env|next templated "error"end- if Crypto::Bcrypt::Password.new(user.password.not_nil!) != password+ if !Crypto::Bcrypt::Password.new(user.password.not_nil!).verify(password)error_message = translate(locale, "Incorrect password")next templated "error"end@@ -2120,7 +2120,7 @@ post "/delete_account" do |env|PG_DB.exec("DROP MATERIALIZED VIEW #{view_name}")env.request.cookies.each do |cookie|- cookie.expires = Time.new(1990, 1, 1)+ cookie.expires = Time.utc(1990, 1, 1)env.response.cookies << cookieendenddiff --git a/src/invidious/helpers/tokens.cr b/src/invidious/helpers/tokens.crindex 31b70c3b..f946fc2c 100644--- a/src/invidious/helpers/tokens.cr+++ b/src/invidious/helpers/tokens.cr@@ -86,7 +86,7 @@ def validate_request(token, session, request, key, db, locale = nil)if token["nonce"]? && (nonce = db.query_one?("SELECT * FROM nonces WHERE nonce = $1", token["nonce"], as: {String, Time}))if nonce[1] > Time.utc- db.exec("UPDATE nonces SET expire = $1 WHERE nonce = $2", Time.new(1990, 1, 1), nonce[0])+ db.exec("UPDATE nonces SET expire = $1 WHERE nonce = $2", Time.utc(1990, 1, 1), nonce[0])elseraise translate(locale, "Erroneous token")enddiff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.crindex 37cc2eb8..3ed067ad 100644--- a/src/invidious/helpers/utils.cr+++ b/src/invidious/helpers/utils.cr@@ -90,7 +90,7 @@ def decode_time(string)millis = /(?<millis>\d+)ms/.match(string).try &.["millis"].try &.to_fmillis ||= 0- time = hours * 3600 + minutes * 60 + seconds + millis / 1000+ time = hours * 3600 + minutes * 60 + seconds + millis // 1000endreturn time@@ -99,7 +99,7 @@ enddef decode_date(string : String)# String matches 'YYYY'if string.match(/^\d{4}/)- return Time.new(string.to_i, 1, 1)+ return Time.utc(string.to_i, 1, 1)end# Try to parse as format Jul 10, 2000@@ -145,11 +145,11 @@ def recode_date(time : Time, locale)span = Time.utc - timeif span.total_days > 365.0- span = translate(locale, "`x` years", (span.total_days.to_i / 365).to_s)+ span = translate(locale, "`x` years", (span.total_days.to_i // 365).to_s)elsif span.total_days > 30.0- span = translate(locale, "`x` months", (span.total_days.to_i / 30).to_s)+ span = translate(locale, "`x` months", (span.total_days.to_i // 30).to_s)elsif span.total_days > 7.0- span = translate(locale, "`x` weeks", (span.total_days.to_i / 7).to_s)+ span = translate(locale, "`x` weeks", (span.total_days.to_i // 7).to_s)elsif span.total_hours > 24.0span = translate(locale, "`x` days", (span.total_days.to_i).to_s)elsif span.total_minutes > 60.0@@ -194,11 +194,11 @@ def number_to_short_text(number)text = text.rchop(".0")- if number / 1_000_000_000 != 0+ if number // 1_000_000_000 != 0text += "B"- elsif number / 1_000_000 != 0+ elsif number // 1_000_000 != 0text += "M"- elsif number / 1000 != 0+ elsif number // 1000 != 0text += "K"enddiff --git a/src/invidious/playlists.cr b/src/invidious/playlists.crindex 2b3f731e..6eb0fd39 100644--- a/src/invidious/playlists.cr+++ b/src/invidious/playlists.cr@@ -6,7 +6,7 @@ struct PlaylistVideoucid: String,length_seconds: Int32,published: Time,- playlists: Array(String),+ plid: String,index: Int32,live_now: Bool,})@@ -114,8 +114,8 @@ def extract_playlist(plid, nodeset, index)author: author,ucid: ucid,length_seconds: length_seconds,- published: Time.now,- playlists: [plid],+ published: Time.utc,+ plid: plid,index: index + offset,live_now: live_now)diff --git a/src/invidious/videos.cr b/src/invidious/videos.crindex 6f3b4d43..5765d0c8 100644--- a/src/invidious/videos.cr+++ b/src/invidious/videos.cr@@ -973,7 +973,7 @@ def extract_polymer_config(body, html)if publishedparams["published"] = Time.parse(published, "%b %-d, %Y", Time::Location.local).to_unix.to_selse- params["published"] = Time.new(1990, 1, 1).to_unix.to_s+ params["published"] = Time.utc(1990, 1, 1).to_unix.to_sendparams["description_html"] = "<p></p>"diff --git a/src/invidious/views/components/item.ecr b/src/invidious/views/components/item.ecrindex b73ce8a1..78017424 100644--- a/src/invidious/views/components/item.ecr+++ b/src/invidious/views/components/item.ecr@@ -52,7 +52,7 @@</b></p><% when PlaylistVideo %>- <a style="width:100%" href="/watch?v=<%= item.id %>&list=<%= item.playlists[0] %>">+ <a style="width:100%" href="/watch?v=<%= item.id %>&list=<%= item.plid %>"><% if !env.get("preferences").as(Preferences).thin_mode %><div class="thumbnail"><img class="thumbnail" src="/vi/<%= item.id %>/mqdefault.jpg"/>diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecrindex 5daf211e..2f03190a 100644--- a/src/invidious/views/watch.ecr+++ b/src/invidious/views/watch.ecr@@ -148,7 +148,7 @@ var video_data = {<p id="engagement"><%= translate(locale, "Engagement: ") %><%= engagement.round(2) %>%</p><% if video.allowed_regions.size != REGIONS.size %><p id="allowed_regions">- <% if video.allowed_regions.size < REGIONS.size / 2 %>+ <% if video.allowed_regions.size < REGIONS.size // 2 %><%= translate(locale, "Whitelisted regions: ") %><%= video.allowed_regions.join(", ") %><% else %><%= translate(locale, "Blacklisted regions: ") %><%= (REGIONS.to_a - video.allowed_regions).join(", ") %>