about summary refs log tree commit diff
path: root/app/workers
diff options
context:
space:
mode:
authorDarius Kazemi <darius.kazemi@gmail.com>2019-04-30 15:29:28 -0700
committerFire Demon <firedemon@creature.cafe>2020-08-30 05:45:15 -0500
commit6378feffa8935238bdb5f1f1c01fcb102440fe30 (patch)
treeb1eea210ace7eb72a00ab4604c3ec10c5ae4db4b /app/workers
parent4eb49257fc618219709b357fb68f4d6156cab249 (diff)
[Feature, Federation, Port: hometown@b3e6597] Support locally cached inline images [+ Monsterfork additions]
Changes added by Monsterfork:
- Do not limit to only Articles
- Reuse existing media; retroactively using more-detailed descriptions
- Also scrub carrige returns between tags
- Handle download failures
- Attach to statuses and keep track of inlined media
- Handle local edits

Co-authored-by: Fire Demon <firedemon@creature.cafe>
Diffstat (limited to 'app/workers')
-rw-r--r--app/workers/redownload_media_worker.rb19
1 files changed, 18 insertions, 1 deletions
diff --git a/app/workers/redownload_media_worker.rb b/app/workers/redownload_media_worker.rb
index 0638cd0f0..0ead9a7a8 100644
--- a/app/workers/redownload_media_worker.rb
+++ b/app/workers/redownload_media_worker.rb
@@ -11,10 +11,27 @@ class RedownloadMediaWorker
 
     return if media_attachment.remote_url.blank?
 
+    orig_small_url = media_attachment.file.url(:small)
+
     media_attachment.download_file!
     media_attachment.download_thumbnail!
-    media_attachment.save
+
+    if media_attachment.save && media_attachment.inline? && media_attachment.status.present?
+      if unsupported_media_type?(media_attachment.file.content_type)
+        media_attachment.destroy
+        true
+      else
+        media_attachment.status.text.gsub!("#{orig_small_url}##{media_attachment.id}", media_attachment.file.url(:small))
+        media_attachment.status.save
+      end
+    end
   rescue ActiveRecord::RecordNotFound
     true
   end
+
+  private
+
+  def unsupported_media_type?(mime_type)
+    mime_type.present? && !MediaAttachment.supported_mime_types.include?(mime_type)
+  end
 end