about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2019-12-08 15:37:12 +0100
committerGitHub <noreply@github.com>2019-12-08 15:37:12 +0100
commitf3d232381d60cbc93cb7a35285eb24c30cd0aba0 (patch)
tree8265da7bac3c3dee64d577d4d1c148f75d8f594e /app/models
parent6d7daf6154b1edbfe9a0c0b297baab8cd45658f3 (diff)
Add `tootctl media remove-orphans` (#12568)
Diffstat (limited to 'app/models')
-rw-r--r--app/models/media_attachment.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb
index 5d5034a52..573ef5dfc 100644
--- a/app/models/media_attachment.rb
+++ b/app/models/media_attachment.rb
@@ -167,6 +167,18 @@ class MediaAttachment < ApplicationRecord
     audio? || video?
   end
 
+  def variant?(other_file_name)
+    return true if file_file_name == other_file_name
+
+    formats = file.styles.values.map(&:format).compact
+
+    return false if formats.empty?
+
+    extension = File.extname(other_file_name)
+
+    formats.include?(extension.delete('.')) && File.basename(other_file_name, extension) == File.basename(file_file_name, File.extname(file_file_name))
+  end
+
   def to_param
     shortcode
   end