Skip to content

Commit

Permalink
bugfix: Fix file name too long
Browse files Browse the repository at this point in the history
  • Loading branch information
igordepolli committed Jul 5, 2024
1 parent 1845e81 commit b014a66
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/vitals_image/analyzer/url_analyzer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def self.accept?(source)
end

def analyze
file = download
file = download
image = open(file)
mime = Marcel::MimeType.for(Pathname.new file.path)

Expand All @@ -32,9 +32,10 @@ def open(file)
end

def download
uri = URI.parse(source.key)
io = uri.open(ssl_verify_mode: ssl_verify_mode)
downloaded = Tempfile.new([File.basename(uri.path), File.extname(uri.path)], binmode: true)
uri = URI.parse(source.key)
io = uri.open(ssl_verify_mode: ssl_verify_mode)
uri_path = reduce_uri_path(uri.path)
downloaded = Tempfile.new([File.basename(uri_path), File.extname(uri_path)], binmode: true)

if io.is_a?(Tempfile)
FileUtils.mv io.path, downloaded.path
Expand All @@ -46,6 +47,13 @@ def download
downloaded
end

def reduce_uri_path(uri_path)
filename, extension = uri_path.split(".")
filename = filename[0..200]

[filename, extension].join(".")
end

def ssl_verify_mode
VitalsImage.skip_ssl_verification ? OpenSSL::SSL::VERIFY_NONE : nil
end
Expand Down
10 changes: 10 additions & 0 deletions test/analyzer/url_analyzer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,15 @@ class Analyzer::UrlAnalyzerTest < ActiveSupport::TestCase
assert_not vitals_image_sources(:invalid).identified
end
end

test "file name too long" do
vitals_image_sources(:dog).update_column :key, "https://festalab-fixtures.s3.amazonaws.com/dog-#{'a' * 255}.jpg"

with_image_library(:vips) do
assert_nothing_raised do
Analyzer::UrlAnalyzer.new(vitals_image_sources(:dog)).analyze
end
end
end
end
end

0 comments on commit b014a66

Please # to comment.