Fix warnings in Crystal 0.29

pull/592/head
Omar Roth 6 years ago
parent 58995bb3a2
commit 2febc268f7
No known key found for this signature in database
GPG Key ID: B8254FB7EC3D37F2

@ -13,9 +13,10 @@ dependencies:
github: kemalcr/kemal github: kemalcr/kemal
pg: pg:
github: will/crystal-pg github: will/crystal-pg
branch: cafe69e
sqlite3: sqlite3:
github: crystal-lang/crystal-sqlite3 github: crystal-lang/crystal-sqlite3
crystal: 0.28.0 crystal: 0.29.0
license: AGPLv3 license: AGPLv3

@ -1089,7 +1089,7 @@ post "/login" do |env|
PG_DB.exec("UPDATE users SET preferences = $1 WHERE email = $2", preferences.to_json, user.email) PG_DB.exec("UPDATE users SET preferences = $1 WHERE email = $2", preferences.to_json, user.email)
cookie = 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 << cookie env.response.cookies << cookie
end end
@ -1117,7 +1117,7 @@ post "/login" do |env|
next templated "error" next templated "error"
end 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)) sid = Base64.urlsafe_encode(Random::Secure.random_bytes(32))
PG_DB.exec("INSERT INTO session_ids VALUES ($1, $2, $3)", sid, email, Time.utc) 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 preferences # Since this user has already registered, we don't want to overwrite their preferences
if env.request.cookies["PREFS"]? if env.request.cookies["PREFS"]?
cookie = 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 << cookie env.response.cookies << cookie
end end
else else
@ -1260,7 +1260,7 @@ post "/login" do |env|
PG_DB.exec("UPDATE users SET preferences = $1 WHERE email = $2", preferences.to_json, user.email) PG_DB.exec("UPDATE users SET preferences = $1 WHERE email = $2", preferences.to_json, user.email)
cookie = 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 << cookie env.response.cookies << cookie
end end
end end
@ -1294,7 +1294,7 @@ post "/signout" do |env|
PG_DB.exec("DELETE FROM session_ids * WHERE id = $1", sid) PG_DB.exec("DELETE FROM session_ids * WHERE id = $1", sid)
env.request.cookies.each do |cookie| env.request.cookies.each do |cookie|
cookie.expires = Time.new(1990, 1, 1) cookie.expires = Time.utc(1990, 1, 1)
env.response.cookies << cookie env.response.cookies << cookie
end end
end end
@ -2064,7 +2064,7 @@ post "/change_password" do |env|
next templated "error" next templated "error"
end 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") error_message = translate(locale, "Incorrect password")
next templated "error" next templated "error"
end end
@ -2120,7 +2120,7 @@ post "/delete_account" do |env|
PG_DB.exec("DROP MATERIALIZED VIEW #{view_name}") PG_DB.exec("DROP MATERIALIZED VIEW #{view_name}")
env.request.cookies.each do |cookie| env.request.cookies.each do |cookie|
cookie.expires = Time.new(1990, 1, 1) cookie.expires = Time.utc(1990, 1, 1)
env.response.cookies << cookie env.response.cookies << cookie
end end
end end

@ -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 token["nonce"]? && (nonce = db.query_one?("SELECT * FROM nonces WHERE nonce = $1", token["nonce"], as: {String, Time}))
if nonce[1] > Time.utc 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])
else else
raise translate(locale, "Erroneous token") raise translate(locale, "Erroneous token")
end end

@ -90,7 +90,7 @@ def decode_time(string)
millis = /(?<millis>\d+)ms/.match(string).try &.["millis"].try &.to_f millis = /(?<millis>\d+)ms/.match(string).try &.["millis"].try &.to_f
millis ||= 0 millis ||= 0
time = hours * 3600 + minutes * 60 + seconds + millis / 1000 time = hours * 3600 + minutes * 60 + seconds + millis // 1000
end end
return time return time
@ -99,7 +99,7 @@ end
def decode_date(string : String) def decode_date(string : String)
# String matches 'YYYY' # String matches 'YYYY'
if string.match(/^\d{4}/) if string.match(/^\d{4}/)
return Time.new(string.to_i, 1, 1) return Time.utc(string.to_i, 1, 1)
end end
# Try to parse as format Jul 10, 2000 # Try to parse as format Jul 10, 2000
@ -145,11 +145,11 @@ def recode_date(time : Time, locale)
span = Time.utc - time span = Time.utc - time
if span.total_days > 365.0 if 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 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 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.0 elsif span.total_hours > 24.0
span = translate(locale, "`x` days", (span.total_days.to_i).to_s) span = translate(locale, "`x` days", (span.total_days.to_i).to_s)
elsif span.total_minutes > 60.0 elsif span.total_minutes > 60.0
@ -194,11 +194,11 @@ def number_to_short_text(number)
text = text.rchop(".0") text = text.rchop(".0")
if number / 1_000_000_000 != 0 if number // 1_000_000_000 != 0
text += "B" text += "B"
elsif number / 1_000_000 != 0 elsif number // 1_000_000 != 0
text += "M" text += "M"
elsif number / 1000 != 0 elsif number // 1000 != 0
text += "K" text += "K"
end end

@ -6,7 +6,7 @@ struct PlaylistVideo
ucid: String, ucid: String,
length_seconds: Int32, length_seconds: Int32,
published: Time, published: Time,
playlists: Array(String), plid: String,
index: Int32, index: Int32,
live_now: Bool, live_now: Bool,
}) })
@ -114,8 +114,8 @@ def extract_playlist(plid, nodeset, index)
author: author, author: author,
ucid: ucid, ucid: ucid,
length_seconds: length_seconds, length_seconds: length_seconds,
published: Time.now, published: Time.utc,
playlists: [plid], plid: plid,
index: index + offset, index: index + offset,
live_now: live_now live_now: live_now
) )

@ -973,7 +973,7 @@ def extract_polymer_config(body, html)
if published if published
params["published"] = Time.parse(published, "%b %-d, %Y", Time::Location.local).to_unix.to_s params["published"] = Time.parse(published, "%b %-d, %Y", Time::Location.local).to_unix.to_s
else else
params["published"] = Time.new(1990, 1, 1).to_unix.to_s params["published"] = Time.utc(1990, 1, 1).to_unix.to_s
end end
params["description_html"] = "<p></p>" params["description_html"] = "<p></p>"

@ -52,7 +52,7 @@
</b> </b>
</p> </p>
<% when PlaylistVideo %> <% 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 %> <% if !env.get("preferences").as(Preferences).thin_mode %>
<div class="thumbnail"> <div class="thumbnail">
<img class="thumbnail" src="/vi/<%= item.id %>/mqdefault.jpg"/> <img class="thumbnail" src="/vi/<%= item.id %>/mqdefault.jpg"/>

@ -148,7 +148,7 @@ var video_data = {
<p id="engagement"><%= translate(locale, "Engagement: ") %><%= engagement.round(2) %>%</p> <p id="engagement"><%= translate(locale, "Engagement: ") %><%= engagement.round(2) %>%</p>
<% if video.allowed_regions.size != REGIONS.size %> <% if video.allowed_regions.size != REGIONS.size %>
<p id="allowed_regions"> <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(", ") %> <%= translate(locale, "Whitelisted regions: ") %><%= video.allowed_regions.join(", ") %>
<% else %> <% else %>
<%= translate(locale, "Blacklisted regions: ") %><%= (REGIONS.to_a - video.allowed_regions).join(", ") %> <%= translate(locale, "Blacklisted regions: ") %><%= (REGIONS.to_a - video.allowed_regions).join(", ") %>

Loading…
Cancel
Save