From 1c91110464e70e053282a73956754df97559d3d6 Mon Sep 17 00:00:00 2001 From: Samantaz Fox Date: Thu, 20 Jan 2022 16:15:59 +0100 Subject: [PATCH] Fix some 'Lint/ShadowingOuterLocalVar' warnings reported by ameba --- src/invidious/routes/api/v1/authenticated.cr | 4 ++-- src/invidious/routes/api/v1/videos.cr | 6 ++--- src/invidious/routes/video_playback.cr | 24 ++++++++++---------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/invidious/routes/api/v1/authenticated.cr b/src/invidious/routes/api/v1/authenticated.cr index 5d2b4c1c..5da6143b 100644 --- a/src/invidious/routes/api/v1/authenticated.cr +++ b/src/invidious/routes/api/v1/authenticated.cr @@ -138,7 +138,7 @@ module Invidious::Routes::API::V1::Authenticated return error_json(400, "Invalid title.") end - privacy = env.params.json["privacy"]?.try { |privacy| PlaylistPrivacy.parse(privacy.as(String).downcase) } + privacy = env.params.json["privacy"]?.try { |p| PlaylistPrivacy.parse(p.as(String).downcase) } if !privacy return error_json(400, "Invalid privacy setting.") end @@ -175,7 +175,7 @@ module Invidious::Routes::API::V1::Authenticated end title = env.params.json["title"].try &.as(String).delete("<>").byte_slice(0, 150) || playlist.title - privacy = env.params.json["privacy"]?.try { |privacy| PlaylistPrivacy.parse(privacy.as(String).downcase) } || playlist.privacy + privacy = env.params.json["privacy"]?.try { |p| PlaylistPrivacy.parse(p.as(String).downcase) } || playlist.privacy description = env.params.json["description"]?.try &.as(String).delete("\r") || playlist.description if title != playlist.title || diff --git a/src/invidious/routes/api/v1/videos.cr b/src/invidious/routes/api/v1/videos.cr index be0f699b..86eb26ee 100644 --- a/src/invidious/routes/api/v1/videos.cr +++ b/src/invidious/routes/api/v1/videos.cr @@ -71,9 +71,9 @@ module Invidious::Routes::API::V1::Videos env.response.content_type = "text/vtt; charset=UTF-8" if lang - caption = captions.select { |caption| caption.language_code == lang } + caption = captions.select(&.language_code.== lang) else - caption = captions.select { |caption| caption.name == label } + caption = captions.select(&.name.== label) end if caption.empty? @@ -179,7 +179,7 @@ module Invidious::Routes::API::V1::Videos env.response.content_type = "text/vtt" - storyboard = storyboards.select { |storyboard| width == "#{storyboard[:width]}" || height == "#{storyboard[:height]}" } + storyboard = storyboards.select { |sb| width == "#{sb[:width]}" || height == "#{sb[:height]}" } if storyboard.empty? haltf env, 404 diff --git a/src/invidious/routes/video_playback.cr b/src/invidious/routes/video_playback.cr index 8a58b034..f6340c57 100644 --- a/src/invidious/routes/video_playback.cr +++ b/src/invidious/routes/video_playback.cr @@ -75,8 +75,8 @@ module Invidious::Routes::VideoPlayback end begin - client.get(url, headers) do |response| - response.headers.each do |key, value| + client.get(url, headers) do |resp| + resp.headers.each do |key, value| if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase) env.response.headers[key] = value end @@ -84,7 +84,7 @@ module Invidious::Routes::VideoPlayback env.response.headers["Access-Control-Allow-Origin"] = "*" - if location = response.headers["Location"]? + if location = resp.headers["Location"]? location = URI.parse(location) location = "#{location.request_target}&host=#{location.host}" @@ -95,7 +95,7 @@ module Invidious::Routes::VideoPlayback return env.redirect location end - IO.copy(response.body_io, env.response) + IO.copy(resp.body_io, env.response) end rescue ex end @@ -132,15 +132,15 @@ module Invidious::Routes::VideoPlayback headers["Range"] = "bytes=#{chunk_start}-#{chunk_end}" begin - client.get(url, headers) do |response| + client.get(url, headers) do |resp| if first_chunk - if !env.request.headers["Range"]? && response.status_code == 206 + if !env.request.headers["Range"]? && resp.status_code == 206 env.response.status_code = 200 else - env.response.status_code = response.status_code + env.response.status_code = resp.status_code end - response.headers.each do |key, value| + resp.headers.each do |key, value| if !RESPONSE_HEADERS_BLACKLIST.includes?(key.downcase) && key.downcase != "content-range" env.response.headers[key] = value end @@ -148,7 +148,7 @@ module Invidious::Routes::VideoPlayback env.response.headers["Access-Control-Allow-Origin"] = "*" - if location = response.headers["Location"]? + if location = resp.headers["Location"]? location = URI.parse(location) location = "#{location.request_target}&host=#{location.host}#{region ? "®ion=#{region}" : ""}" @@ -161,8 +161,8 @@ module Invidious::Routes::VideoPlayback env.response.headers["Content-Disposition"] = "attachment; filename=\"#{URI.encode_www_form(title)}\"; filename*=UTF-8''#{URI.encode_www_form(title)}" end - if !response.headers.includes_word?("Transfer-Encoding", "chunked") - content_length = response.headers["Content-Range"].split("/")[-1].to_i64 + if !resp.headers.includes_word?("Transfer-Encoding", "chunked") + content_length = resp.headers["Content-Range"].split("/")[-1].to_i64 if env.request.headers["Range"]? env.response.headers["Content-Range"] = "bytes #{range_start}-#{range_end || (content_length - 1)}/#{content_length}" env.response.content_length = ((range_end.try &.+ 1) || content_length) - range_start @@ -172,7 +172,7 @@ module Invidious::Routes::VideoPlayback end end - proxy_file(response, env) + proxy_file(resp, env) end rescue ex if ex.message != "Error reading socket: Connection reset by peer"