From 594b0a78e95752030ed1962e6e996749bf154677 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Tue, 12 Apr 2022 17:56:51 +0200 Subject: [PATCH] Use file mime type for picture by format select Active storage has the mime type stored not the extension. --- app/models/alchemy/picture.rb | 10 ++++------ config/locales/alchemy.en.yml | 1 + 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/models/alchemy/picture.rb b/app/models/alchemy/picture.rb index 29088c2647..1101cf7e40 100644 --- a/app/models/alchemy/picture.rb +++ b/app/models/alchemy/picture.rb @@ -91,7 +91,9 @@ def self.preprocessor_class=(klass) scope :recent, -> { where("#{table_name}.created_at > ?", Time.current - 24.hours).order(:created_at) } scope :deletable, -> { where("#{table_name}.id NOT IN (SELECT picture_id FROM #{EssencePicture.table_name})") } scope :without_tag, -> { left_outer_joins(:taggings).where(gutentag_taggings: { id: nil }) } - scope :by_file_format, ->(format) { where(image_file_format: format) } + scope :by_file_format, ->(file_format) { + with_attached_image_file.joins(:image_file_blob).where(active_storage_blobs: { content_type: file_format }) + } # Class methods @@ -111,14 +113,10 @@ def url_class=(klass) end def alchemy_resource_filters - file_types = file_formats.map do |format| - MiniMime.lookup_by_content_type(format)&.extension - end - [ { name: :by_file_format, - values: file_types, + values: file_formats, }, { name: :misc, diff --git a/config/locales/alchemy.en.yml b/config/locales/alchemy.en.yml index a96ef0c2f3..6ccd7fe8a0 100644 --- a/config/locales/alchemy.en.yml +++ b/config/locales/alchemy.en.yml @@ -118,6 +118,7 @@ en: by_file_format: name: File Type values: + <<: *mime_types gif: GIF Image jpeg: JPG Image png: PNG Image