Class: Riiif::ImagesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/riiif/images_controller.rb

Instance Method Summary collapse

Instance Method Details

#infoObject



31
32
33
34
35
36
37
38
39
# File 'app/controllers/riiif/images_controller.rb', line 31

def info
  image = model.new(image_id)
  if authorization_service.can?(:info, image)
    headers['Access-Control-Allow-Origin'] = '*'
    render json: image.info.merge(server_info), content_type: 'application/ld+json'
  else
    render json: { error: 'unauthorized' }, status: :unauthorized
  end
end

#redirectObject

this is a workaround for github.com/rails/rails/issues/25087



42
43
44
45
# File 'app/controllers/riiif/images_controller.rb', line 42

def redirect
  # This was attempted with just info_path, but it gave a NoMethodError
  redirect_to Riiif::Engine.routes.url_helpers.info_path(params[:id])
end

#showObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/riiif/images_controller.rb', line 9

def show
  begin
    image = model.new(image_id)
    status = if authorization_service.can?(:show, image)
               :ok
             else
               :unauthorized
             end
  rescue ImageNotFoundError
    status = :not_found
  end

  image = not_found_image unless status == :ok

  data = image.render(params.permit(:region, :size, :rotation, :quality, :format))
  headers['Access-Control-Allow-Origin'] = '*'
  send_data data,
            status: status,
            type: Mime::Type.lookup_by_extension(params[:format]),
            disposition: 'inline'
end