6a6a37a67b
fixes: #3853 - Introduced DISABLE_GRAVATAR Global Config, which will stop chatwoot from making API requests to gravatar - Cleaned up avatar-related logic and centralized it into the avatarable concern - Added specs for the missing cases - Added migration for existing installations to move the avatar to attachment, rather than making the API that results in 404.
15 lines
511 B
Ruby
15 lines
511 B
Ruby
class Avatar::AvatarFromUrlJob < ApplicationJob
|
|
queue_as :default
|
|
|
|
def perform(avatarable, avatar_url)
|
|
return unless avatarable.respond_to?(:avatar)
|
|
|
|
avatar_file = Down.download(
|
|
avatar_url,
|
|
max_size: 15 * 1024 * 1024
|
|
)
|
|
avatarable.avatar.attach(io: avatar_file, filename: avatar_file.original_filename, content_type: avatar_file.content_type)
|
|
rescue Down::NotFound, Down::Error => e
|
|
Rails.logger.error "Exception: invalid avatar url #{avatar_url} : #{e.message}"
|
|
end
|
|
end
|