Fix warnings in Crystal 0.29

This commit is contained in:
Omar Roth 2019-06-07 20:23:37 -05:00
parent 58995bb3a2
commit 2febc268f7
No known key found for this signature in database
GPG key ID: B8254FB7EC3D37F2
8 changed files with 24 additions and 23 deletions

View file

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

View file

@ -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 << cookie
end
@ -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 preferences
if 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
end
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)
cookie = env.request.cookies["PREFS"]
cookie.expires = Time.new(1990, 1, 1)
cookie.expires = Time.utc(1990, 1, 1)
env.response.cookies << cookie
end
end
@ -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 << cookie
end
end
@ -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 << cookie
end
end

View file

@ -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])
else
raise translate(locale, "Erroneous token")
end

View file

@ -90,7 +90,7 @@ def decode_time(string)
millis = /(?<millis>\d+)ms/.match(string).try &.["millis"].try &.to_f
millis ||= 0
time = hours * 3600 + minutes * 60 + seconds + millis / 1000
time = hours * 3600 + minutes * 60 + seconds + millis // 1000
end
return time
@ -99,7 +99,7 @@ end
def 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 - time
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
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.0
span = 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 != 0
text += "B"
elsif number / 1_000_000 != 0
elsif number // 1_000_000 != 0
text += "M"
elsif number / 1000 != 0
elsif number // 1000 != 0
text += "K"
end

View file

@ -6,7 +6,7 @@ struct PlaylistVideo
ucid: 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
)

View file

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

View file

@ -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"/>

View file

@ -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(", ") %>