Files
leadchat/app/jobs/avatar/avatar_from_url_job.rb
Pranav 9acb0d86b5 fix: Disable enqueueing Avatar jobs if the URL is invalid (#12035)
- Add a new queue purgable
- Disable enqueuing the job if URL is invalid
2025-07-24 12:56:39 +04:00

29 lines
739 B
Ruby

class Avatar::AvatarFromUrlJob < ApplicationJob
queue_as :purgable
def perform(avatarable, avatar_url)
return unless avatarable.respond_to?(:avatar)
avatar_file = Down.download(
avatar_url,
max_size: 15 * 1024 * 1024
)
if valid_image?(avatar_file)
avatarable.avatar.attach(io: avatar_file, filename: avatar_file.original_filename,
content_type: avatar_file.content_type)
end
rescue Down::NotFound, Down::Error => e
Rails.logger.error "Exception: invalid avatar url #{avatar_url} : #{e.message}"
end
private
def valid_image?(file)
return false if file.original_filename.blank?
# TODO: check if the file is an actual image
true
end
end