Sha256: 6ab9da3c2d12d8d72ef3b8b85f7b4466aea3af18e20dad9babe8f16a7a6d9300

Contents?: true

Size: 876 Bytes

Versions: 5

Compression:

Stored size: 876 Bytes

Contents

module Riiif
  class FileSystemFileResolver < AbstractFileSystemResolver
    attr_writer :input_types

    # @return a string suitable for a globbing match
    #   e.g. /base/path/67352ccc-d1b0-11e1-89ae-279075081939.{jp2,tiff,png}
    #   or nil when the id is not valid
    def pattern(id)
      return unless validate_identifier(id: id)
      ::File.join(base_path, "#{id}.{#{input_types.join(',')}}")
    end

    private

      # @return [Boolean] true if the id matches the regex
      def validate_identifier(id:, regex: identifier_regex)
        return true if id.to_s =~ regex
        Rails.logger.warn "Invalid characters in id `#{id}`"
        false
      end

      # Matches on word characters dashes and colons
      def identifier_regex
        /^[\w\-:]+$/
      end

      def input_types
        @input_types ||= %w(png jpg tif tiff jp2)
      end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
riiif-2.7.0 app/resolvers/riiif/file_system_file_resolver.rb
riiif-2.6.0 app/resolvers/riiif/file_system_file_resolver.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/riiif-2.5.0/app/resolvers/riiif/file_system_file_resolver.rb
riiif-2.5.0 app/resolvers/riiif/file_system_file_resolver.rb
riiif-2.4.0 app/resolvers/riiif/file_system_file_resolver.rb