From f3d232381d60cbc93cb7a35285eb24c30cd0aba0 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 8 Dec 2019 15:37:12 +0100 Subject: Add `tootctl media remove-orphans` (#12568) --- app/models/media_attachment.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'app/models/media_attachment.rb') 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 -- cgit