mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
Rename FileHelper.is_image?
-> FileHelper.is_supported_image?
.
This commit is contained in:
parent
d59e635a77
commit
e1b16e445e
11 changed files with 16 additions and 16 deletions
|
@ -72,7 +72,7 @@ class UploadsController < ApplicationController
|
||||||
content_type: MiniMime.lookup_by_filename(upload.original_filename)&.content_type,
|
content_type: MiniMime.lookup_by_filename(upload.original_filename)&.content_type,
|
||||||
}
|
}
|
||||||
opts[:disposition] = "inline" if params[:inline]
|
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)
|
send_file(Discourse.store.path_for(upload), opts)
|
||||||
else
|
else
|
||||||
render_404
|
render_404
|
||||||
|
|
|
@ -26,7 +26,7 @@ module Jobs
|
||||||
|
|
||||||
# Special case: Images
|
# Special case: Images
|
||||||
# If the link is to an image, put the filename as the title
|
# 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)
|
uri = URI(topic_link.url)
|
||||||
filename = File.basename(uri.path)
|
filename = File.basename(uri.path)
|
||||||
crawled = (TopicLink.where(id: topic_link.id).update_all(["title = ?, crawled_at = CURRENT_TIMESTAMP", filename]) == 1)
|
crawled = (TopicLink.where(id: topic_link.id).update_all(["title = ?, crawled_at = CURRENT_TIMESTAMP", filename]) == 1)
|
||||||
|
|
|
@ -112,7 +112,7 @@ class Upload < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def fix_dimensions!
|
def fix_dimensions!
|
||||||
return if !FileHelper.is_image?("image.#{extension}")
|
return if !FileHelper.is_supported_image?("image.#{extension}")
|
||||||
|
|
||||||
path =
|
path =
|
||||||
if local?
|
if local?
|
||||||
|
@ -219,7 +219,7 @@ class Upload < ActiveRecord::Base
|
||||||
upload.sha1 = Upload.generate_digest(path)
|
upload.sha1 = Upload.generate_digest(path)
|
||||||
end
|
end
|
||||||
# optimize if image
|
# 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
|
# store to new location & update the filesize
|
||||||
File.open(path) do |f|
|
File.open(path) do |f|
|
||||||
upload.url = Discourse.store.store_upload(f, upload)
|
upload.url = Discourse.store.store_upload(f, upload)
|
||||||
|
|
|
@ -910,7 +910,7 @@ module Email
|
||||||
end
|
end
|
||||||
|
|
||||||
def attachment_markdown(upload)
|
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}'>"
|
"<img src='#{upload.url}' width='#{upload.width}' height='#{upload.height}'>"
|
||||||
else
|
else
|
||||||
"<a class='attachment' href='#{upload.url}'>#{upload.original_filename}</a> (#{number_to_human_size(upload.filesize)})"
|
"<a class='attachment' href='#{upload.url}'>#{upload.original_filename}</a> (#{number_to_human_size(upload.filesize)})"
|
||||||
|
|
|
@ -11,8 +11,8 @@ class FileHelper
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.is_image?(filename)
|
def self.is_supported_image?(filename)
|
||||||
filename =~ images_regexp
|
filename =~ supported_images_regexp
|
||||||
end
|
end
|
||||||
|
|
||||||
class FakeIO
|
class FakeIO
|
||||||
|
@ -104,8 +104,8 @@ class FileHelper
|
||||||
@@supported_images ||= Set.new %w{jpg jpeg png gif tif tiff bmp svg webp ico}
|
@@supported_images ||= Set.new %w{jpg jpeg png gif tif tiff bmp svg webp ico}
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.images_regexp
|
def self.supported_images_regexp
|
||||||
@@images_regexp ||= /\.(#{supported_images.to_a.join("|")})$/i
|
@@supported_images_regexp ||= /\.(#{supported_images.to_a.join("|")})$/i
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -39,7 +39,7 @@ module FileStore
|
||||||
content_type: opts[:content_type].presence || MiniMime.lookup_by_filename(filename)&.content_type
|
content_type: opts[:content_type].presence || MiniMime.lookup_by_filename(filename)&.content_type
|
||||||
}
|
}
|
||||||
# add a "content disposition" header for "attachments"
|
# 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
|
# if this fails, it will throw an exception
|
||||||
path = @s3_helper.upload(file, path, options)
|
path = @s3_helper.upload(file, path, options)
|
||||||
# return the upload url
|
# return the upload url
|
||||||
|
|
|
@ -37,8 +37,8 @@ class UploadCreator
|
||||||
# test for image regardless of input
|
# test for image regardless of input
|
||||||
@image_info = FastImage.new(@file) rescue nil
|
@image_info = FastImage.new(@file) rescue nil
|
||||||
|
|
||||||
is_image = FileHelper.is_image?(@filename)
|
is_image = FileHelper.is_supported_image?(@filename)
|
||||||
is_image ||= @image_info && FileHelper.is_image?("test.#{@image_info.type}")
|
is_image ||= @image_info && FileHelper.is_supported_image?("test.#{@image_info.type}")
|
||||||
|
|
||||||
if is_image
|
if is_image
|
||||||
extract_image_info!
|
extract_image_info!
|
||||||
|
|
|
@ -36,7 +36,7 @@ class UrlHelper
|
||||||
|
|
||||||
uri = URI.parse(url)
|
uri = URI.parse(url)
|
||||||
filename = File.basename(uri.path)
|
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
|
no_cdn = SiteSetting.login_required || SiteSetting.prevent_anons_from_downloading_files
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ class Validators::UploadValidator < ActiveModel::Validator
|
||||||
extension = File.extname(upload.original_filename)[1..-1] || ""
|
extension = File.extname(upload.original_filename)[1..-1] || ""
|
||||||
|
|
||||||
if is_authorized?(upload, extension)
|
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)
|
authorized_image_extension(upload, extension)
|
||||||
maximum_image_file_size(upload)
|
maximum_image_file_size(upload)
|
||||||
else
|
else
|
||||||
|
|
|
@ -11,7 +11,7 @@ Upload.where("lower(extension) in (?)", ['jpg', 'jpeg', 'gif', 'png', 'bmp', 'ti
|
||||||
count += 1
|
count += 1
|
||||||
print "\r%8d".freeze % count
|
print "\r%8d".freeze % count
|
||||||
absolute_path = Discourse.store.path_for(upload)
|
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
|
file = File.new(absolute_path) rescue nil
|
||||||
next unless file
|
next unless file
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ module ImportScripts
|
||||||
end
|
end
|
||||||
|
|
||||||
def html_for_upload(upload, display_filename)
|
def html_for_upload(upload, display_filename)
|
||||||
if FileHelper.is_image?(upload.url)
|
if FileHelper.is_supported_image?(upload.url)
|
||||||
embedded_image_html(upload)
|
embedded_image_html(upload)
|
||||||
else
|
else
|
||||||
attachment_html(upload, display_filename)
|
attachment_html(upload, display_filename)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue