about summary refs log tree commit diff
path: root/app/models/media_attachment.rb
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2019-12-12 15:40:06 +0100
committerThibaut Girka <thib@sitedethib.com>2019-12-12 15:40:06 +0100
commitbe4849c08306cce930ea27e1f8097ffb774f75c6 (patch)
tree7eb7528245c671cdf908e07c3d630e7639d575bb /app/models/media_attachment.rb
parent246addd5b33a172600342af3fb6fb5e4c80ad95e (diff)
parentd08a4979462352f83b1deddaa6209f7b6078ed26 (diff)
Merge branch 'master' into glitch-soc/merge-upstream
Conflicts:
- app/controllers/application_controller.rb
  Minor conflict due to glitch-soc's theming system
Diffstat (limited to 'app/models/media_attachment.rb')
-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 e05879188..880599028 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