From 625216d8e14cd567bffe14fb73343f27e81dcb1d Mon Sep 17 00:00:00 2001 From: Claire Date: Sun, 27 Nov 2022 20:39:05 +0100 Subject: [PATCH] Fix attachments of edited statuses not being fetched (#21565) * Fix attachments of edited statuses not being fetched * Fix tests --- app/services/activitypub/process_status_update_service.rb | 8 +++++++- .../activitypub/process_status_update_service_spec.rb | 6 +++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/services/activitypub/process_status_update_service.rb b/app/services/activitypub/process_status_update_service.rb index addd5fc274..a0605b1a3b 100644 --- a/app/services/activitypub/process_status_update_service.rb +++ b/app/services/activitypub/process_status_update_service.rb @@ -92,7 +92,13 @@ class ActivityPub::ProcessStatusUpdateService < BaseService next if unsupported_media_type?(media_attachment_parser.file_content_type) || skip_download? - RedownloadMediaWorker.perform_async(media_attachment.id) if media_attachment.remote_url_previously_changed? || media_attachment.thumbnail_remote_url_previously_changed? + begin + media_attachment.download_file! if media_attachment.remote_url_previously_changed? + media_attachment.download_thumbnail! if media_attachment.thumbnail_remote_url_previously_changed? + media_attachment.save + rescue Mastodon::UnexpectedResponseError, HTTP::TimeoutError, HTTP::ConnectionError, OpenSSL::SSL::SSLError + RedownloadMediaWorker.perform_in(rand(30..600).seconds, media_attachment.id) + end rescue Addressable::URI::InvalidURIError => e Rails.logger.debug "Invalid URL in attachment: #{e}" end diff --git a/spec/services/activitypub/process_status_update_service_spec.rb b/spec/services/activitypub/process_status_update_service_spec.rb index 481572742b..750369d57f 100644 --- a/spec/services/activitypub/process_status_update_service_spec.rb +++ b/spec/services/activitypub/process_status_update_service_spec.rb @@ -331,7 +331,7 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do context 'originally without media attachments' do before do - allow(RedownloadMediaWorker).to receive(:perform_async) + stub_request(:get, 'https://example.com/foo.png').to_return(body: attachment_fixture('emojo.png')) subject.call(status, json) end @@ -355,8 +355,8 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService, type: :service do expect(media_attachment.remote_url).to eq 'https://example.com/foo.png' end - it 'queues download of media attachments' do - expect(RedownloadMediaWorker).to have_received(:perform_async) + it 'fetches the attachment' do + expect(a_request(:get, 'https://example.com/foo.png')).to have_been_made end it 'records media change in edit' do