discourse/app/jobs/regular/create_thumbnails.rb
Régis Hanol bb0c2813ac FEATURE: generate (avatar) thumbnails in a background task
FIX: keep the "uploading..." indicator until the server replies via the MessageBus
FIX: text was disapearing when uploading an avatar

PERF: always use a region for S3 (defaults to 'us-east-1')
FEATURE: ApplyCDN middleware when using S3
FIX: use the same pattern to store files on S3 and locally
PERF: keep a local cache of uploads when generating thumbnails
FEATURE: migrate_to_s3 rake task
2015-05-25 17:59:00 +02:00

34 lines
728 B
Ruby

module Jobs
class CreateThumbnails < Jobs::Base
def execute(args)
upload_id = args[:upload_id]
type = args[:type]
raise Discourse::InvalidParameters.new(:upload_id) if upload_id.blank?
raise Discourse::InvalidParameters.new(:type) if type.blank?
# only need to generate thumbnails for avatars
return if type != "avatar"
upload = Upload.find(upload_id)
self.send("create_thumbnails_for_#{type}", upload)
end
PIXELS ||= [1, 2]
def create_thumbnails_for_avatar(upload)
PIXELS.each do |pixel|
Discourse.avatar_sizes.each do |size|
size *= pixel
upload.create_thumbnail!(size, size)
end
end
end
end
end