2020-10-16 18:41:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Jobs
|
|
|
|
class UpdateAnimatedUploads < ::Jobs::Scheduled
|
|
|
|
every 1.hour
|
|
|
|
|
2024-10-16 10:09:07 +08:00
|
|
|
MAX_PROCESSED_GIF_IMAGES = 200
|
2020-10-16 18:41:27 +08:00
|
|
|
|
|
|
|
def execute(args)
|
|
|
|
Upload
|
|
|
|
.where("extension = 'gif' OR (extension IS NULL AND original_filename LIKE '%.gif')")
|
|
|
|
.where(animated: nil)
|
|
|
|
.limit(MAX_PROCESSED_GIF_IMAGES)
|
|
|
|
.each do |upload|
|
|
|
|
uri = Discourse.store.path_for(upload) || upload.url
|
2020-10-21 00:11:43 +08:00
|
|
|
upload.animated = FastImage.animated?(uri)
|
|
|
|
upload.save(validate: false)
|
2020-10-16 18:41:27 +08:00
|
|
|
upload.optimized_images.destroy_all if upload.animated
|
|
|
|
end
|
|
|
|
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|