Rename FileHelper.is_image? -> FileHelper.is_supported_image?.

This commit is contained in:
Guo Xiang Tan 2018-09-10 10:22:45 +08:00
parent d59e635a77
commit e1b16e445e
11 changed files with 16 additions and 16 deletions

View File

@ -72,7 +72,7 @@ class UploadsController < ApplicationController
content_type: MiniMime.lookup_by_filename(upload.original_filename)&.content_type,
}
opts[:disposition] = "inline" if params[:inline]
opts[:disposition] ||= "attachment" unless FileHelper.is_image?(upload.original_filename)
opts[:disposition] ||= "attachment" unless FileHelper.is_supported_image?(upload.original_filename)
send_file(Discourse.store.path_for(upload), opts)
else
render_404

View File

@ -26,7 +26,7 @@ module Jobs
# Special case: Images
# If the link is to an image, put the filename as the title
if FileHelper.is_image?(topic_link.url)
if FileHelper.is_supported_image?(topic_link.url)
uri = URI(topic_link.url)
filename = File.basename(uri.path)
crawled = (TopicLink.where(id: topic_link.id).update_all(["title = ?, crawled_at = CURRENT_TIMESTAMP", filename]) == 1)

View File

@ -112,7 +112,7 @@ class Upload < ActiveRecord::Base
end
def fix_dimensions!
return if !FileHelper.is_image?("image.#{extension}")
return if !FileHelper.is_supported_image?("image.#{extension}")
path =
if local?
@ -219,7 +219,7 @@ class Upload < ActiveRecord::Base
upload.sha1 = Upload.generate_digest(path)
end
# optimize if image
FileHelper.optimize_image!(path) if FileHelper.is_image?(File.basename(path))
FileHelper.optimize_image!(path) if FileHelper.is_supported_image?(File.basename(path))
# store to new location & update the filesize
File.open(path) do |f|
upload.url = Discourse.store.store_upload(f, upload)

View File

@ -910,7 +910,7 @@ module Email
end
def attachment_markdown(upload)
if FileHelper.is_image?(upload.original_filename)
if FileHelper.is_supported_image?(upload.original_filename)
"<img src='#{upload.url}' width='#{upload.width}' height='#{upload.height}'>"
else
"<a class='attachment' href='#{upload.url}'>#{upload.original_filename}</a> (#{number_to_human_size(upload.filesize)})"

View File

@ -11,8 +11,8 @@ class FileHelper
)
end
def self.is_image?(filename)
filename =~ images_regexp
def self.is_supported_image?(filename)
filename =~ supported_images_regexp
end
class FakeIO
@ -104,8 +104,8 @@ class FileHelper
@@supported_images ||= Set.new %w{jpg jpeg png gif tif tiff bmp svg webp ico}
end
def self.images_regexp
@@images_regexp ||= /\.(#{supported_images.to_a.join("|")})$/i
def self.supported_images_regexp
@@supported_images_regexp ||= /\.(#{supported_images.to_a.join("|")})$/i
end
end

View File

@ -39,7 +39,7 @@ module FileStore
content_type: opts[:content_type].presence || MiniMime.lookup_by_filename(filename)&.content_type
}
# add a "content disposition" header for "attachments"
options[:content_disposition] = "attachment; filename=\"#{filename}\"" unless FileHelper.is_image?(filename)
options[:content_disposition] = "attachment; filename=\"#{filename}\"" unless FileHelper.is_supported_image?(filename)
# if this fails, it will throw an exception
path = @s3_helper.upload(file, path, options)
# return the upload url

View File

@ -37,8 +37,8 @@ class UploadCreator
# test for image regardless of input
@image_info = FastImage.new(@file) rescue nil
is_image = FileHelper.is_image?(@filename)
is_image ||= @image_info && FileHelper.is_image?("test.#{@image_info.type}")
is_image = FileHelper.is_supported_image?(@filename)
is_image ||= @image_info && FileHelper.is_supported_image?("test.#{@image_info.type}")
if is_image
extract_image_info!

View File

@ -36,7 +36,7 @@ class UrlHelper
uri = URI.parse(url)
filename = File.basename(uri.path)
is_attachment = !FileHelper.is_image?(filename)
is_attachment = !FileHelper.is_supported_image?(filename)
no_cdn = SiteSetting.login_required || SiteSetting.prevent_anons_from_downloading_files

View File

@ -18,7 +18,7 @@ class Validators::UploadValidator < ActiveModel::Validator
extension = File.extname(upload.original_filename)[1..-1] || ""
if is_authorized?(upload, extension)
if FileHelper.is_image?(upload.original_filename)
if FileHelper.is_supported_image?(upload.original_filename)
authorized_image_extension(upload, extension)
maximum_image_file_size(upload)
else

View File

@ -11,7 +11,7 @@ Upload.where("lower(extension) in (?)", ['jpg', 'jpeg', 'gif', 'png', 'bmp', 'ti
count += 1
print "\r%8d".freeze % count
absolute_path = Discourse.store.path_for(upload)
if absolute_path && FileHelper.is_image?(upload.original_filename)
if absolute_path && FileHelper.is_supported_image?(upload.original_filename)
file = File.new(absolute_path) rescue nil
next unless file

View File

@ -40,7 +40,7 @@ module ImportScripts
end
def html_for_upload(upload, display_filename)
if FileHelper.is_image?(upload.url)
if FileHelper.is_supported_image?(upload.url)
embedded_image_html(upload)
else
attachment_html(upload, display_filename)