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