2015-05-25 11:59:00 -04:00
|
|
|
module Jobs
|
|
|
|
|
|
|
|
class CreateThumbnails < Jobs::Base
|
|
|
|
|
|
|
|
def execute(args)
|
|
|
|
type = args[:type]
|
2015-05-29 12:10:19 -04:00
|
|
|
upload_id = args[:upload_id]
|
2015-05-25 11:59:00 -04:00
|
|
|
|
|
|
|
raise Discourse::InvalidParameters.new(:type) if type.blank?
|
2015-05-29 12:10:19 -04:00
|
|
|
raise Discourse::InvalidParameters.new(:upload_id) if upload_id.blank?
|
2015-05-25 11:59:00 -04:00
|
|
|
|
|
|
|
# only need to generate thumbnails for avatars
|
|
|
|
return if type != "avatar"
|
|
|
|
|
|
|
|
upload = Upload.find(upload_id)
|
|
|
|
|
2015-05-29 12:10:19 -04:00
|
|
|
user_id = args[:user_id] || upload.user_id
|
|
|
|
user = User.find(user_id)
|
|
|
|
|
|
|
|
self.send("create_thumbnails_for_#{type}", upload, user)
|
2015-05-25 11:59:00 -04:00
|
|
|
end
|
|
|
|
|
2015-05-29 12:10:19 -04:00
|
|
|
def create_thumbnails_for_avatar(upload, user)
|
2015-05-29 03:57:54 -04:00
|
|
|
Discourse.avatar_sizes.each do |size|
|
|
|
|
OptimizedImage.create_for(upload, size, size, allow_animation: SiteSetting.allow_animated_avatars)
|
2015-05-25 11:59:00 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|