diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/serializers/rest/media_attachment_serializer.rb | 1 | ||||
-rw-r--r-- | app/workers/domain_block_worker.rb | 3 | ||||
-rw-r--r-- | app/workers/fetch_media_worker.rb | 19 |
3 files changed, 22 insertions, 1 deletions
diff --git a/app/serializers/rest/media_attachment_serializer.rb b/app/serializers/rest/media_attachment_serializer.rb index 1b3498ea4..35467ded8 100644 --- a/app/serializers/rest/media_attachment_serializer.rb +++ b/app/serializers/rest/media_attachment_serializer.rb @@ -13,6 +13,7 @@ class REST::MediaAttachmentSerializer < ActiveModel::Serializer def url if object.needs_redownload? + FetchMediaWorker.perform_async(object.id) media_proxy_url(object.id, :original) else full_asset_url(object.file.url(:original)) diff --git a/app/workers/domain_block_worker.rb b/app/workers/domain_block_worker.rb index 884477829..d51c387dc 100644 --- a/app/workers/domain_block_worker.rb +++ b/app/workers/domain_block_worker.rb @@ -4,7 +4,8 @@ class DomainBlockWorker include Sidekiq::Worker def perform(domain_block_id) - BlockDomainService.new.call(DomainBlock.find(domain_block_id)) + domain_block = DomainBlock.find(domain_block_id) + BlockDomainService.new.call(domain_block) rescue ActiveRecord::RecordNotFound true end diff --git a/app/workers/fetch_media_worker.rb b/app/workers/fetch_media_worker.rb new file mode 100644 index 000000000..5dc8cc84b --- /dev/null +++ b/app/workers/fetch_media_worker.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +class FetchMediaWorker + include Sidekiq::Worker + + def perform(media_attachment_id, remote_url = nil) + object = MediaAttachment.find(media_attachment_id.to_i) + if remote_url.nil? + return if object.remote_url.nil? + else + object.remote_url = remote_url + end + object.file_remote_url = object.remote_url + object.created_at = Time.now.utc + object.save! + rescue ActiveRecord::RecordNotFound + true + end +end |