Sha256: 25a31cebf42b8d59f6a1144d358a46f86f48a2577e4465d74193125ae41e8a6d

Contents?: true

Size: 1.35 KB

Versions: 5

Compression:

Stored size: 1.35 KB

Contents

module CurationConcerns
  class ThumbnailPathService
    class << self
      # @param [Work, FileSet] the object to get the thumbnail for
      # @return [String] a path to the thumbnail
      def call(object)
        return default_image unless object.thumbnail_id

        thumb = fetch_thumbnail(object)
        return unless thumb
        if thumb.audio?
          audio_image
        elsif thumbnail?(thumb)
          Rails.application.routes.url_helpers.download_path(object.thumbnail_id, file: 'thumbnail')
        else
          default_image
        end
      end

      def fetch_thumbnail(object)
        return object if object.thumbnail_id == object.id
        ::FileSet.find(object.thumbnail_id)
      rescue ActiveFedora::ObjectNotFoundError
        Rails.logger.error("Couldn't find thumbnail #{object.thumbnail_id} for #{object.id}")
        nil
      end

      def default_image
        ActionController::Base.helpers.image_path 'default.png'
      end

      def audio_image
        ActionController::Base.helpers.image_path 'audio.png'
      end

      # @return true if there a file on disk for this object, otherwise false
      def thumbnail?(thumb)
        File.exist?(thumbnail_filepath(thumb))
      end

      def thumbnail_filepath(thumb)
        CurationConcerns::DerivativePath.derivative_path_for_reference(thumb, 'thumbnail')
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
curation_concerns-1.0.0.beta6 app/services/curation_concerns/thumbnail_path_service.rb
curation_concerns-1.0.0.beta5 app/services/curation_concerns/thumbnail_path_service.rb
curation_concerns-1.0.0.beta4 app/services/curation_concerns/thumbnail_path_service.rb
curation_concerns-1.0.0.beta3 app/services/curation_concerns/thumbnail_path_service.rb
curation_concerns-1.0.0.beta2 app/services/curation_concerns/thumbnail_path_service.rb