diff --git a/shard.yml b/shard.yml index 0d54a2f9..0e33c2fa 100644 --- a/shard.yml +++ b/shard.yml @@ -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 diff --git a/src/invidious.cr b/src/invidious.cr index 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 << 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 diff --git a/src/invidious/helpers/tokens.cr b/src/invidious/helpers/tokens.cr index 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]) else raise translate(locale, "Erroneous token") end diff --git a/src/invidious/helpers/utils.cr b/src/invidious/helpers/utils.cr index 37cc2eb8..3ed067ad 100644 --- a/src/invidious/helpers/utils.cr +++ b/src/invidious/helpers/utils.cr @@ -90,7 +90,7 @@ def decode_time(string) 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 diff --git a/src/invidious/playlists.cr b/src/invidious/playlists.cr index 2b3f731e..6eb0fd39 100644 --- a/src/invidious/playlists.cr +++ b/src/invidious/playlists.cr @@ -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 ) diff --git a/src/invidious/videos.cr b/src/invidious/videos.cr index 6f3b4d43..5765d0c8 100644 --- a/src/invidious/videos.cr +++ b/src/invidious/videos.cr @@ -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"] = "

" diff --git a/src/invidious/views/components/item.ecr b/src/invidious/views/components/item.ecr index b73ce8a1..78017424 100644 --- a/src/invidious/views/components/item.ecr +++ b/src/invidious/views/components/item.ecr @@ -52,7 +52,7 @@

<% when PlaylistVideo %> - + <% if !env.get("preferences").as(Preferences).thin_mode %>
diff --git a/src/invidious/views/watch.ecr b/src/invidious/views/watch.ecr index 5daf211e..2f03190a 100644 --- a/src/invidious/views/watch.ecr +++ b/src/invidious/views/watch.ecr @@ -148,7 +148,7 @@ var video_data = {

<%= translate(locale, "Engagement: ") %><%= engagement.round(2) %>%

<% if video.allowed_regions.size != REGIONS.size %>

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