mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 06:29:30 +08:00
FIX: Use File.size instead of IO.size
This commit is contained in:
parent
d87520a2cf
commit
827ea641b0
|
@ -61,15 +61,15 @@ class UploadsController < ApplicationController
|
|||
end
|
||||
|
||||
# allow users to upload large images that will be automatically reduced to allowed size
|
||||
if tempfile && tempfile.size > 0 && SiteSetting.max_image_size_kb > 0 && FileHelper.is_image?(filename)
|
||||
if tempfile && File.size(tempfile.path) > 0 && SiteSetting.max_image_size_kb > 0 && FileHelper.is_image?(filename)
|
||||
attempt = 5
|
||||
while attempt > 0 && tempfile.size > SiteSetting.max_image_size_kb.kilobytes
|
||||
while attempt > 0 && File.size(tempfile.path) > SiteSetting.max_image_size_kb.kilobytes
|
||||
OptimizedImage.downsize(tempfile.path, tempfile.path, "80%", allow_animation: SiteSetting.allow_animated_thumbnails)
|
||||
attempt -= 1
|
||||
end
|
||||
end
|
||||
|
||||
upload = Upload.create_for(current_user.id, tempfile, filename, tempfile.size, content_type: content_type, image_type: type)
|
||||
upload = Upload.create_for(current_user.id, tempfile, filename, File.size(tempfile.path), content_type: content_type, image_type: type)
|
||||
|
||||
if upload.errors.empty? && current_user.admin?
|
||||
retain_hours = params[:retain_hours].to_i
|
||||
|
|
|
@ -36,9 +36,9 @@ module Jobs
|
|||
rescue Discourse::InvalidParameters
|
||||
end
|
||||
if hotlinked
|
||||
if hotlinked.size <= @max_size
|
||||
if File.size(hotlinked.path) <= @max_size
|
||||
filename = File.basename(URI.parse(src).path)
|
||||
upload = Upload.create_for(post.user_id, hotlinked, filename, hotlinked.size, { origin: src })
|
||||
upload = Upload.create_for(post.user_id, hotlinked, filename, File.size(hotlinked.path), { origin: src })
|
||||
downloaded_urls[src] = upload.url
|
||||
else
|
||||
Rails.logger.error("Failed to pull hotlinked image: #{src} - Image is bigger than #{@max_size}")
|
||||
|
|
|
@ -20,7 +20,7 @@ class UserAvatar < ActiveRecord::Base
|
|||
max = Discourse.avatar_sizes.max
|
||||
gravatar_url = "http://www.gravatar.com/avatar/#{email_hash}.png?s=#{max}&d=404"
|
||||
tempfile = FileHelper.download(gravatar_url, SiteSetting.max_image_size_kb.kilobytes, "gravatar")
|
||||
upload = Upload.create_for(user.id, tempfile, 'gravatar.png', tempfile.size, origin: gravatar_url, image_type: "avatar")
|
||||
upload = Upload.create_for(user.id, tempfile, 'gravatar.png', File.size(tempfile.path), origin: gravatar_url, image_type: "avatar")
|
||||
|
||||
if gravatar_upload_id != upload.id
|
||||
gravatar_upload.try(:destroy!)
|
||||
|
@ -68,7 +68,7 @@ class UserAvatar < ActiveRecord::Base
|
|||
ext = FastImage.type(tempfile).to_s
|
||||
tempfile.rewind
|
||||
|
||||
upload = Upload.create_for(user.id, tempfile, "external-avatar." + ext, tempfile.size, origin: avatar_url, image_type: "avatar")
|
||||
upload = Upload.create_for(user.id, tempfile, "external-avatar." + ext, File.size(tempfile.path), origin: avatar_url, image_type: "avatar")
|
||||
user.uploaded_avatar_id = upload.id
|
||||
|
||||
unless user.user_avatar
|
||||
|
|
Loading…
Reference in New Issue
Block a user