diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb index d5a09c084d3..d2442d21101 100644 --- a/app/controllers/uploads_controller.rb +++ b/app/controllers/uploads_controller.rb @@ -14,7 +14,7 @@ class UploadsController < ApplicationController # check the file size (note: this might also be done in the web server) filesize = File.size(file.tempfile) type = SiteSetting.authorized_image?(file) ? "image" : "attachment" - max_size_kb = SiteSetting.send("max_#{type}_size_kb") * 1024 + max_size_kb = SiteSetting.send("max_#{type}_size_kb").kilobytes return render status: 413, text: I18n.t("upload.#{type}s.too_large", max_size_kb: max_size_kb) if filesize > max_size_kb upload = Upload.create_for(current_user.id, file, filesize) diff --git a/app/jobs/regular/pull_hotlinked_images.rb b/app/jobs/regular/pull_hotlinked_images.rb index 7d29923ee92..ad323923737 100644 --- a/app/jobs/regular/pull_hotlinked_images.rb +++ b/app/jobs/regular/pull_hotlinked_images.rb @@ -4,7 +4,7 @@ module Jobs def initialize # maximum size of the file in bytes - @max_size = SiteSetting.max_image_size_kb * 1024 + @max_size = SiteSetting.max_image_size_kb.kilobytes end def execute(args) @@ -34,7 +34,7 @@ module Jobs upload = Upload.create_for(post.user_id, file, hotlinked.size, src) downloaded_urls[src] = upload.url else - Rails.logger.warn("Failed to pull hotlinked image: #{src} - Image is bigger than #{@max_size}") + puts "Failed to pull hotlinked image: #{src} - Image is bigger than #{@max_size}" end end # have we successfuly downloaded that file? @@ -54,7 +54,7 @@ module Jobs raw.gsub!(src, "") end rescue => e - Rails.logger.error("Failed to pull hotlinked image: #{src}\n" + e.message + "\n" + e.backtrace.join("\n")) + puts "Failed to pull hotlinked image: #{src}\n" + e.message + "\n" + e.backtrace.join("\n") ensure # close & delete the temp file hotlinked && hotlinked.close! @@ -81,6 +81,7 @@ module Jobs end def download(url) + return if @max_size <= 0 extension = File.extname(URI.parse(url).path) tmp = Tempfile.new(["discourse-hotlinked", extension]) diff --git a/app/models/site_setting.rb b/app/models/site_setting.rb index 5921bb7206a..9f02c21ab3a 100644 --- a/app/models/site_setting.rb +++ b/app/models/site_setting.rb @@ -56,7 +56,7 @@ class SiteSetting < ActiveRecord::Base setting(:title_prettify, true) client_setting(:max_image_size_kb, 2048) - client_setting(:max_attachment_size_kb, 1024) + client_setting(:max_attachment_size_kb, 1.kilobyte) client_setting(:authorized_extensions, '.jpg|.jpeg|.png|.gif') # settings only available server side diff --git a/app/services/uri_adapter.rb b/app/services/uri_adapter.rb index 23b48776959..bf7f1c19dae 100644 --- a/app/services/uri_adapter.rb +++ b/app/services/uri_adapter.rb @@ -17,7 +17,7 @@ class UriAdapter end def copy_to_tempfile(src) - while data = src.read(16*1024) + while data = src.read(16.kilobytes) tempfile.write(data) end src.close @@ -30,7 +30,7 @@ class UriAdapter end def build_uploaded_file - return if (SiteSetting.max_image_size_kb * 1024) < file_size + return if SiteSetting.max_image_size_kb.kilobytes < file_size copy_to_tempfile(content) content_type = content.content_type if content.respond_to?(:content_type) @@ -61,4 +61,4 @@ class TempfileFactory def basename File.basename(@name, extension).gsub(ILLEGAL_FILENAME_CHARACTERS, '_') end -end \ No newline at end of file +end diff --git a/lib/avatar_upload_service.rb b/lib/avatar_upload_service.rb index 3a9cb838827..4a19d49da3c 100644 --- a/lib/avatar_upload_service.rb +++ b/lib/avatar_upload_service.rb @@ -33,7 +33,7 @@ class AvatarUploadPolicy end def max_size_kb - SiteSetting.max_image_size_kb * 1024 + SiteSetting.max_image_size_kb.kilobytes end def too_big? diff --git a/lib/mem_info.rb b/lib/mem_info.rb index 91d17c4e528..6c227cdfd33 100644 --- a/lib/mem_info.rb +++ b/lib/mem_info.rb @@ -8,7 +8,7 @@ class MemInfo system = `uname`.strip if system == "Darwin" s = `sysctl -n hw.memsize`.strip - s.to_i / 1024 + s.to_i / 1.kilobyte else s = `grep MemTotal /proc/meminfo` /(\d+)/.match(s)[0].try(:to_i)