Class: Riiif::ImagesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Riiif::ImagesController
- Defined in:
- app/controllers/riiif/images_controller.rb
Instance Method Summary collapse
- #info ⇒ Object
- #info_options ⇒ Object
-
#redirect ⇒ Object
this is a workaround for github.com/rails/rails/issues/25087.
- #show ⇒ Object
Instance Method Details
#info ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/riiif/images_controller.rb', line 33 def info image = model.new(image_id) if .can?(:info, image) image_info = image.info return render json: { error: 'no info' }, status: :not_found unless image_info.valid? headers['Access-Control-Allow-Origin'] = '*' # Set a Cache-Control header expires_in cache_expires, public: public_cache? render json: image_info.to_h.merge(server_info), content_type: 'application/ld+json' else render json: { error: 'unauthorized' }, status: :unauthorized end end |
#info_options ⇒ Object
48 49 50 51 |
# File 'app/controllers/riiif/images_controller.rb', line 48 def response.headers['Access-Control-Allow-Headers'] = 'Authorization' self.response_body = '' end |
#redirect ⇒ Object
this is a workaround for github.com/rails/rails/issues/25087
54 55 56 57 |
# File 'app/controllers/riiif/images_controller.rb', line 54 def redirect # This was attempted with just info_path, but it gave a NoMethodError redirect_to riiif.info_path(params[:id]) end |
#show ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/riiif/images_controller.rb', line 9 def show begin image = model.new(image_id) status = if .can?(:show, image) :ok else :unauthorized end rescue ImageNotFoundError status = :not_found end image = error_image(status) unless status == :ok data = image.render(image_request_params) headers['Access-Control-Allow-Origin'] = '*' # Set a Cache-Control header expires_in cache_expires, public: public_cache? if status == :ok send_data data, status: status, type: Mime::Type.lookup_by_extension(params[:format]), disposition: 'inline' end |