diff --git a/app/controllers/downloads_controller.rb b/app/controllers/downloads_controller.rb index babccb7c..3d796f1e 100644 --- a/app/controllers/downloads_controller.rb +++ b/app/controllers/downloads_controller.rb @@ -29,7 +29,7 @@ def track end def blob - @blob ||= ActiveStorage::Blob.find_by(key: params[:key]) + @blob ||= ActiveStorage::Blob.find_by(key: params[:key].split(".").first) end def add_cache_header diff --git a/app/models/application_record.rb b/app/models/application_record.rb index e1f4e5cc..3cd9135f 100644 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -1,10 +1,10 @@ class ApplicationRecord < ActiveRecord::Base self.abstract_class = true - def blob_url(attachment, variant: nil, placeholder: nil) + def blob_url(attachment, variant: nil, placeholder: nil, ext: nil) if attachment.attached? key = variant ? attachment.variant(variant).processed.key : attachment.blob.key - "#{App.content_base_url}/blob/#{key}" + "#{App.content_base_url}/blob/#{key}#{".#{ext}" if ext}" elsif placeholder "/placeholders/#{placeholder}" end diff --git a/app/models/concerns/has_cover_art.rb b/app/models/concerns/has_cover_art.rb index e7aecc2c..6a4c7e85 100644 --- a/app/models/concerns/has_cover_art.rb +++ b/app/models/concerns/has_cover_art.rb @@ -5,19 +5,21 @@ module HasCoverArt included do # rubocop:disable Metrics/BlockLength def cover_art_urls - { - large: blob_url(cover_art, placeholder: "cover-art-large.jpg"), - medium: blob_url(cover_art, variant: :medium, placeholder: "cover-art-medium.jpg"), - small: blob_url(cover_art, variant: :small, placeholder: "cover-art-small.jpg") - } + %i[large medium small].index_with do |size| + blob_url \ + cover_art, + **(size == :large ? {} : { variant: size }), + placeholder: "cover-art-#{size}.jpg", + ext: :jpg + end end def album_cover_url - blob_url(album_cover, placeholder: "cover-art-large.jpg") + blob_url(album_cover, placeholder: "cover-art-large.jpg", ext: :jpg) end def album_zip_url - blob_url(album_zip) + blob_url(album_zip, ext: :zip) end def cover_art_path diff --git a/app/models/track.rb b/app/models/track.rb index 479ce26b..89129c8f 100644 --- a/app/models/track.rb +++ b/app/models/track.rb @@ -51,11 +51,11 @@ def generate_slug(force: false) end def mp3_url - blob_url(mp3_audio, placeholder: "audio.mp3") + blob_url(mp3_audio, placeholder: "audio.mp3", ext: :mp3) end def waveform_image_url - blob_url(png_waveform, placeholder: "waveform.png") + blob_url(png_waveform, placeholder: "waveform.png", ext: :png) end def urls