mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 18:30:26 -06:00
Fix the build.
This commit is contained in:
parent
b69f72853f
commit
16c0ebe8a8
@ -20,6 +20,7 @@ module Jobs
|
||||
downloaded = FileHelper.download(
|
||||
src,
|
||||
max_file_size: @max_size,
|
||||
retain_on_max_file_size_exceeded: true,
|
||||
tmp_file_name: "discourse-hotlinked",
|
||||
follow_redirect: true
|
||||
)
|
||||
|
@ -25,7 +25,8 @@ class FileHelper
|
||||
follow_redirect: false,
|
||||
read_timeout: 5,
|
||||
skip_rate_limit: false,
|
||||
verbose: false)
|
||||
verbose: false,
|
||||
retain_on_max_file_size_exceeded: false)
|
||||
|
||||
url = "https:" + url if url.start_with?("//")
|
||||
raise Discourse::InvalidParameters.new(:url) unless url =~ /^https?:\/\//
|
||||
@ -68,8 +69,11 @@ class FileHelper
|
||||
tmp.write(chunk)
|
||||
|
||||
if tmp.size > max_file_size
|
||||
unless retain_on_max_file_size_exceeded
|
||||
tmp.close
|
||||
tmp = nil
|
||||
end
|
||||
|
||||
throw :done
|
||||
end
|
||||
end
|
||||
|
@ -59,6 +59,8 @@ describe FileHelper do
|
||||
)
|
||||
|
||||
expect(Base64.encode64(tmpfile.read)).to eq(Base64.encode64(png))
|
||||
ensure
|
||||
tmpfile&.close
|
||||
end
|
||||
|
||||
it "works with a protocol relative url" do
|
||||
@ -69,6 +71,8 @@ describe FileHelper do
|
||||
)
|
||||
|
||||
expect(Base64.encode64(tmpfile.read)).to eq(Base64.encode64(png))
|
||||
ensure
|
||||
tmpfile&.close
|
||||
end
|
||||
|
||||
describe 'when max_file_size is exceeded' do
|
||||
@ -81,6 +85,19 @@ describe FileHelper do
|
||||
|
||||
expect(tmpfile).to eq(nil)
|
||||
end
|
||||
|
||||
it 'is able to retain the tmpfile' do
|
||||
tmpfile = FileHelper.download(
|
||||
"//eviltrout.com/trout.png",
|
||||
max_file_size: 1,
|
||||
tmp_file_name: 'trouttmp',
|
||||
retain_on_max_file_size_exceeded: true
|
||||
)
|
||||
|
||||
expect(tmpfile.closed?).to eq(false)
|
||||
ensure
|
||||
tmpfile&.close
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when url is a jpeg' do
|
||||
@ -98,6 +115,8 @@ describe FileHelper do
|
||||
)
|
||||
|
||||
expect(File.extname(tmpfile)).to eq('.png')
|
||||
ensure
|
||||
tmpfile&.close
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -103,12 +103,12 @@ describe Jobs::PullHotlinkedImages do
|
||||
end
|
||||
|
||||
it 'all combinations' do
|
||||
post = Fabricate(:post, raw: "
|
||||
post = Fabricate(:post, raw: <<~BODY)
|
||||
<img src='#{image_url}'>
|
||||
#{url}
|
||||
<img src='#{broken_image_url}'>
|
||||
<a href='#{url}'><img src='#{large_image_url}'></a>
|
||||
")
|
||||
BODY
|
||||
|
||||
Jobs::ProcessPost.new.execute(post_id: post.id)
|
||||
Jobs::PullHotlinkedImages.new.execute(post_id: post.id)
|
||||
|
Loading…
Reference in New Issue
Block a user