Sha256: 4ed93b5011e153867ac6acb147d451160fad6b166eb42fd8bf03239fde1dcdc8

Contents?: true

Size: 1.87 KB

Versions: 30

Compression:

Stored size: 1.87 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
        return call(thumb) unless thumb.is_a?(::FileSet)
        if thumb.audio?
          audio_image
        elsif thumbnail?(thumb)
          thumbnail_path(thumb)
        else
          default_image
        end
      end

      protected

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

        # @return the network path to the thumbnail
        # @param [FileSet] thumbnail the object that is the thumbnail
        def thumbnail_path(thumbnail)
          Rails.application.routes.url_helpers.download_path(thumbnail.id,
                                                             file: 'thumbnail')
        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
        # @param [FileSet] thumbnail the object that is the thumbnail
        def thumbnail?(thumb)
          File.exist?(thumbnail_filepath(thumb))
        end

        # @param [FileSet] thumbnail the object that is the thumbnail
        def thumbnail_filepath(thumb)
          CurationConcerns::DerivativePath.derivative_path_for_reference(thumb, 'thumbnail')
        end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
curation_concerns-1.7.8 app/services/curation_concerns/thumbnail_path_service.rb
curation_concerns-1.7.7 app/services/curation_concerns/thumbnail_path_service.rb
curation_concerns-2.0.0 app/services/curation_concerns/thumbnail_path_service.rb
curation_concerns-2.0.0.rc2 app/services/curation_concerns/thumbnail_path_service.rb
curation_concerns-1.7.6 app/services/curation_concerns/thumbnail_path_service.rb
curation_concerns-1.7.5 app/services/curation_concerns/thumbnail_path_service.rb
curation_concerns-1.7.4 app/services/curation_concerns/thumbnail_path_service.rb
curation_concerns-1.7.3 app/services/curation_concerns/thumbnail_path_service.rb
curation_concerns-1.7.2 app/services/curation_concerns/thumbnail_path_service.rb
curation_concerns-2.0.0.rc1 app/services/curation_concerns/thumbnail_path_service.rb
curation_concerns-1.7.1 app/services/curation_concerns/thumbnail_path_service.rb
curation_concerns-1.7.0 app/services/curation_concerns/thumbnail_path_service.rb
curation_concerns-1.7.0.beta1 app/services/curation_concerns/thumbnail_path_service.rb
curation_concerns-1.6.3 app/services/curation_concerns/thumbnail_path_service.rb
curation_concerns-1.6.2 app/services/curation_concerns/thumbnail_path_service.rb
curation_concerns-1.6.1 app/services/curation_concerns/thumbnail_path_service.rb
curation_concerns-1.6.0 app/services/curation_concerns/thumbnail_path_service.rb
curation_concerns-1.5.0 app/services/curation_concerns/thumbnail_path_service.rb
curation_concerns-1.4.0 app/services/curation_concerns/thumbnail_path_service.rb
curation_concerns-1.3.3 app/services/curation_concerns/thumbnail_path_service.rb