Created
January 27, 2020 20:00
-
-
Save rococodogs/52677a33ef57ff9b55b1e334e7c2829d to your computer and use it in GitHub Desktop.
cantaloupe delegate file wip
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
# frozen_string_literal: true | |
class CustomDelegate | |
attr_accessor :context | |
## | |
# Returns authorization status for the current request. Will be called upon | |
# all requests to all public endpoints. | |
# | |
# Implementations should assume that the underlying resource is available, | |
# and not try to check for it. | |
# | |
# Possible return values: | |
# | |
# 1. Boolean true/false, indicating whether the request is fully authorized | |
# or not. If false, the client will receive a 403 Forbidden response. | |
# 2. Hash with a `status_code` key. | |
# a. If it corresponds to an integer from 200-299, the request is | |
# authorized. | |
# b. If it corresponds to an integer from 300-399: | |
# i. If the hash also contains a `location` key corresponding to a | |
# URI string, the request will be redirected to that URI using | |
# that code. | |
# ii. If the hash also contains `scale_numerator` and | |
# `scale_denominator` keys, the request will be | |
# redirected using that code to a virtual reduced-scale version of | |
# the source image. | |
# c. If it corresponds to 401, the hash must include a `challenge` key | |
# corresponding to a WWW-Authenticate header value. | |
# | |
# @param options [Hash] Empty hash. | |
# @return [Boolean,Hash<String,Object>] See above. | |
# | |
def authorize(options = {}) | |
true | |
end | |
## | |
# Used to add additional keys to an information JSON response. See the | |
# [Image API specification](http://iiif.io/api/image/2.1/#image-information). | |
# | |
# @param options [Hash] Empty hash. | |
# @return [Hash] Hash that will be merged into an IIIF Image API 2.x | |
# information response. Return an empty hash to add nothing. | |
# | |
def extra_iiif_information_response_keys(options = {}) | |
=begin | |
Example: | |
{ | |
'attribution' => 'Copyright My Great Organization. All rights '\ | |
'reserved.', | |
'license' => 'http://example.org/license.html', | |
'logo' => 'http://example.org/logo.png', | |
'service' => { | |
'@context' => 'http://iiif.io/api/annex/services/physdim/1/context.json', | |
'profile' => 'http://iiif.io/api/annex/services/physdim', | |
'physicalScale' => 0.0025, | |
'physicalUnits' => 'in' | |
} | |
} | |
=end | |
{} | |
end | |
## | |
# Tells the server which source to use for the given identifier. | |
# | |
# @param options [Hash] Empty hash. | |
# @return [String] Source name. | |
# | |
def source(options = {}) | |
end | |
## | |
# N.B.: this method should not try to perform authorization. `authorize()` | |
# should be used instead. | |
# | |
# @param options [Hash] Empty hash. | |
# @return [String,nil] Absolute pathname of the image corresponding to the | |
# given identifier, or nil if not found. | |
# | |
def filesystemsource_pathname(options = {}) | |
prefix = ENV.fetch('IIIF_IMAGE_PREFIX', nil) | |
suffix = ENV.fetch('IIIF_IMAGE_SUFFIX', nil) | |
raw_id = context['identifier'] | |
path = raw_id.scan(/\w\w?/).join('/') | |
path += suffix unless suffix.nil? | |
File.join(prefix, path).to_s | |
end | |
# | |
# methods we're not currently using | |
# | |
def azurestoragesource_blob_key(options = {}); end | |
def httpsource_resource_info(options = {}); end | |
def jdbcsource_database_identifier(options = {}); end | |
def jdbcsource_media_type(options = {}); end | |
def jdbcsource_lookup_sql(options = {}); end | |
## | |
# N.B.: this method should not try to perform authorization. `authorize()` | |
# should be used instead. | |
# | |
# @param options [Hash] Empty hash. | |
# @return [Hash<String,Object>,nil] Hash containing `bucket` and `key` keys; | |
# or nil if not found. | |
# | |
def s3source_object_info(options = {}); end | |
def overlay(options = {}); end | |
def redactions(options = {}) | |
[] | |
end | |
def metadata(options = {}) | |
nil | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment