diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2019-09-10 15:29:12 +0200 |
---|---|---|
committer | multiple creatures <dev@multiple-creature.party> | 2020-02-21 03:56:30 -0600 |
commit | 941c1d41ffebfcd96d6709219c50b1482f930e9b (patch) | |
tree | cf0c982dce4f261af2aed71c9fdc7413dd5e0ce2 /app/lib | |
parent | 68456c90ce53b5a9852d30ea83d28e14b8c0bac0 (diff) |
port tootsuite#11775 to monsterfork: Add retry for failed media downloads and `tootctl media refresh`
Diffstat (limited to 'app/lib')
-rw-r--r-- | app/lib/activitypub/activity/create.rb | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb index fc751a44d..b4755fea5 100644 --- a/app/lib/activitypub/activity/create.rb +++ b/app/lib/activitypub/activity/create.rb @@ -296,22 +296,25 @@ class ActivityPub::Activity::Create < ActivityPub::Activity media_attachments = [] as_array(@object['attachment']).each do |attachment| - next if attachment['url'].blank? + next if attachment['url'].blank? || media_attachments.size >= 4 - href = Addressable::URI.parse(attachment['url']).normalize.to_s - media_attachment = MediaAttachment.create(account: @account, remote_url: href, description: attachment['name'].presence, focus: attachment['focalPoint'], blurhash: supported_blurhash?(attachment['blurhash']) ? attachment['blurhash'] : nil) - media_attachments << media_attachment + begin + href = Addressable::URI.parse(attachment['url']).normalize.to_s + media_attachment = MediaAttachment.create(account: @account, remote_url: href, description: attachment['name'].presence, focus: attachment['focalPoint'], blurhash: supported_blurhash?(attachment['blurhash']) ? attachment['blurhash'] : nil) + media_attachments << media_attachment - next if unsupported_media_type?(attachment['mediaType']) || skip_download?(href) + next if unsupported_media_type?(attachment['mediaType']) || skip_download? - media_attachment.file_remote_url = href - media_attachment.save + media_attachment.file_remote_url = href + media_attachment.save + rescue Mastodon::UnexpectedResponseError, HTTP::TimeoutError, HTTP::ConnectionError, OpenSSL::SSL::SSLError + RedownloadMediaWorker.perform_in(rand(30..600).seconds, media_attachment.id) + end end media_attachments rescue Addressable::URI::InvalidURIError => e - Rails.logger.debug e - + Rails.logger.debug "Invalid URL in attachment: #{e}" media_attachments end @@ -483,7 +486,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity components.present? && components.none? { |comp| comp > 5 } end - def skip_download?(remote_url = nil) + def skip_download? return @skip_download if defined?(@skip_download) @skip_download ||= DomainBlock.reject_media?(@account.domain) end |