Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
51 changed files
with
283 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ | |
/node_modules | ||
/public/packs/ | ||
/public/packs-test/ | ||
/public/uploads/ | ||
/test | ||
/screenshots | ||
/coverage | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,6 @@ | |
/config/master.key | ||
/public/packs | ||
/public/packs-test | ||
/public/uploads | ||
/public/assets | ||
/node_modules | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
require "open-uri" | ||
class AttachCoverImageFromDiscogsJob < ApplicationJob | ||
queue_as :default | ||
|
||
def perform(discogs_imageable) | ||
image_url = DiscogsApi.image(discogs_imageable) | ||
return unless image_url.present? | ||
|
||
image_file = OpenURI.open_uri(image_url) | ||
content_type = image_file.content_type | ||
image_format = Mime::Type.lookup(content_type).symbol | ||
return unless image_format.present? | ||
|
||
discogs_imageable.cover_image.attach( | ||
io: image_file, | ||
filename: "cover.#{image_format}", | ||
content_type: content_type | ||
) | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,37 @@ | ||
module ImageableConcern | ||
extend ActiveSupport::Concern | ||
|
||
ALLOWED_IMAGE_CONTENT_TYPES = %w[image/jpeg image/png].freeze | ||
|
||
included do | ||
mount_uploader :image, ImageUploader | ||
has_one_attached :cover_image do |attachable| | ||
attachable.variant :small, resize_to_fill: [200, 200] | ||
attachable.variant :medium, resize_to_fill: [300, 300], preprocessed: true | ||
attachable.variant :large, resize_to_fill: [400, 400] | ||
end | ||
|
||
validate :content_type_of_cover_image | ||
end | ||
|
||
def has_image? | ||
image.file.present? | ||
def has_cover_image? | ||
cover_image.attached? | ||
end | ||
|
||
def attach_image_from_discogs | ||
AttachImageFromDiscogsJob.perform_later(self) if needs_image_from_discogs? | ||
def attach_cover_image_from_discogs | ||
AttachCoverImageFromDiscogsJob.perform_later(self) if needs_cover_image_from_discogs? | ||
end | ||
|
||
private | ||
|
||
def needs_image_from_discogs? | ||
Setting.discogs_token.present? && !has_image? && !unknown? | ||
def needs_cover_image_from_discogs? | ||
Setting.discogs_token.present? && !has_cover_image? && !unknown? | ||
end | ||
|
||
def content_type_of_cover_image | ||
return unless cover_image.attached? | ||
|
||
unless cover_image.content_type.in?(ALLOWED_IMAGE_CONTENT_TYPES) | ||
errors.add(:cover_image, :invalid_content_type) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.