media file: fix exception on empty files.
This may happen if a user uploads from a source that returns an error HTTP response with no data.
This commit is contained in:
@@ -7,7 +7,6 @@ require "danbooru/http/session"
|
||||
|
||||
module Danbooru
|
||||
class Http
|
||||
class DownloadError < StandardError; end
|
||||
class FileTooLargeError < StandardError; end
|
||||
|
||||
DEFAULT_TIMEOUT = 10
|
||||
@@ -111,7 +110,6 @@ module Danbooru
|
||||
end
|
||||
|
||||
def download_response(response, file: Tempfile.new("danbooru-download-", binmode: true))
|
||||
raise DownloadError, response if response.status != 200
|
||||
raise FileTooLargeError, response if @max_size && response.content_length.to_i > @max_size
|
||||
|
||||
size = 0
|
||||
|
||||
@@ -43,6 +43,8 @@ class MediaFile
|
||||
else
|
||||
:bin
|
||||
end
|
||||
rescue EOFError
|
||||
:bin
|
||||
end
|
||||
|
||||
def self.videos_enabled?
|
||||
|
||||
0
test/files/test-empty.bin
Normal file
0
test/files/test-empty.bin
Normal file
@@ -98,6 +98,10 @@ class MediaFileTest < ActiveSupport::TestCase
|
||||
should "determine the correct extension for a flash file" do
|
||||
assert_equal(:swf, MediaFile.open("test/files/compressed.swf").file_ext)
|
||||
end
|
||||
|
||||
should "not fail for empty files" do
|
||||
assert_equal(:bin, MediaFile.open("test/files/test-empty.bin").file_ext)
|
||||
end
|
||||
end
|
||||
|
||||
should "determine the correct md5 for a jpeg file" do
|
||||
|
||||
Reference in New Issue
Block a user