hyrax-iiif_av 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 7175259d686db59f6e4d217489dc482160627417
4
- data.tar.gz: 625d46c52ad2e322f43404ce59d463e2a2fa66a1
2
+ SHA256:
3
+ metadata.gz: 155e529eda163eb4a1783739f0a2e3fd42315f1768a8448f5186b9e2ee6edd89
4
+ data.tar.gz: fb381ed8f314b4b88a1c4d7b626d08576bd7044ba97360047b08b229e687a2e2
5
5
  SHA512:
6
- metadata.gz: 84d57cae07a601937a22832fe3591b3303de66f766bdc1fafec4a03f7baa588761c7c28f271650918d9c90da6444d2f2476fb12c85a1a66c78c9a3a39b6b9eb1
7
- data.tar.gz: c5f7569a394a53b5de49406402cb30d3d26cd741a97b3a0810651726e9f9ecf8f1ac2f406869d7ba3b0f2b1c2b7e8225baaa5f4435ca04012bcf25c74ced2aaa
6
+ metadata.gz: a3622bb4c1657924c6c66667d4ad53148d4c4fc159ff4236583b1a4faf099ccbac562ed51f1fcd707cc7a910d537724ebfb511e2945f2c93497a6e81c090f6ea
7
+ data.tar.gz: d360b921021bc1fb1369d9a10787ec5aab50386efa7667365089afe82e704940d9ea19ac9c9180c0bc7e7da98b50e821160f8bf1f4e9275c62d5379d3265ea9c
@@ -0,0 +1,48 @@
1
+ version: 2.1
2
+ orbs:
3
+ samvera: samvera/circleci-orb@1.0
4
+ jobs:
5
+ bundle_and_test:
6
+ parameters:
7
+ ruby_version:
8
+ type: string
9
+ default: 2.5.5
10
+ bundler_version:
11
+ type: string
12
+ default: 2.3.0
13
+
14
+ executor:
15
+ name: 'samvera/ruby_fcrepo_solr'
16
+ ruby_version: << parameters.ruby_version >>
17
+ solr_version: 7-slim
18
+
19
+ working_directory: ~/project
20
+
21
+ environment:
22
+ ENGINE_CART_RAILS_OPTIONS: --skip-git --skip-bundle --skip-listen --skip-spring --skip-yarn --skip-keeps --skip-coffee --skip-puma --skip-test
23
+
24
+ steps:
25
+ - samvera/cached_checkout
26
+
27
+ - samvera/bundle:
28
+ ruby_version: << parameters.ruby_version >>
29
+ bundler_version: << parameters.bundler_version >>
30
+
31
+ - samvera/engine_cart_generate:
32
+ cache_key: v2-internal-test-app-{{ checksum "hyrax-iiif_av.gemspec" }}-{{ checksum "spec/test_app_templates/lib/generators/test_app_generator.rb" }}-{{ checksum "lib/generators/hyrax/iiif_av/install_generator.rb" }}
33
+
34
+ - samvera/install_solr_core:
35
+ solr_config_path: .internal_test_app/solr/conf
36
+
37
+ - samvera/bundle:
38
+ ruby_version: << parameters.ruby_version >>
39
+ bundler_version: << parameters.bundler_version >>
40
+
41
+ - samvera/parallel_rspec
42
+
43
+ workflows:
44
+ ci:
45
+ jobs:
46
+ - bundle_and_test:
47
+ name: ruby2-7
48
+ ruby_version: 2.7.5
@@ -0,0 +1,33 @@
1
+ name: Release Gem
2
+ on:
3
+ workflow_dispatch:
4
+ push:
5
+ tags:
6
+ - -v*
7
+
8
+ jobs:
9
+ push:
10
+ if: github.repository == 'samvera-labs/hyrax-iiif_av'
11
+ name: Push gem to RubyGems.org
12
+ runs-on: ubuntu-latest
13
+
14
+ permissions:
15
+ id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
16
+ contents: write # IMPORTANT: this permission is required for `rake release` to push the release tag
17
+
18
+ environment: release
19
+
20
+ steps:
21
+ # Set up
22
+ - uses: actions/checkout@v5
23
+ with:
24
+ persist-credentials: false
25
+ - name: Set up Ruby
26
+ uses: ruby/setup-ruby@v1
27
+ with:
28
+ bundler-cache: true
29
+ ruby-version: ruby
30
+
31
+ # Release
32
+ - uses: rubygems/release-gem@v1
33
+
data/.gitignore CHANGED
@@ -4,3 +4,4 @@ pkg/
4
4
  Gemfile.lock
5
5
  .internal_test_app
6
6
  .byebug_history
7
+ vendor/bundle/**
data/.rubocop.yml CHANGED
@@ -2,7 +2,7 @@ inherit_gem:
2
2
  bixby: bixby_default.yml
3
3
 
4
4
  AllCops:
5
- TargetRubyVersion: 2.3
5
+ TargetRubyVersion: 2.4
6
6
  DisplayCopNames: true
7
7
 
8
8
  Naming/FileName:
@@ -20,7 +20,11 @@ Metrics/BlockLength:
20
20
  - 'lib/hyrax/iiif_av/spec/shared_specs/displays_content.rb'
21
21
  - 'lib/hyrax/iiif_av/spec/shared_specs/displays_iiif_av.rb'
22
22
  - 'spec/controllers/generic_works_controller_spec.rb'
23
+ - 'spec/controllers/iiif_av_controller_spec.rb'
24
+ - 'spec/factories/users.rb'
23
25
  - 'spec/helpers/iiif_av_helper_spec.rb'
26
+ - 'spec/requests/auth_controller_behavior_spec.rb'
27
+ - 'spec/support/features/session_helpers.rb'
24
28
 
25
29
  RSpec/VerifiedDoubles:
26
30
  Exclude:
@@ -31,3 +35,15 @@ RSpec/VerifiedDoubles:
31
35
  RSpec/ExampleLength:
32
36
  Exclude:
33
37
  - 'lib/hyrax/iiif_av/spec/shared_specs/displays_content.rb'
38
+
39
+ Metrics/ModuleLength:
40
+ Exclude:
41
+ - 'app/presenters/concerns/hyrax/iiif_av/displays_content.rb'
42
+
43
+ Metrics/MethodLength:
44
+ Exclude:
45
+ - 'app/presenters/concerns/hyrax/iiif_av/displays_content.rb'
46
+
47
+ Rails/OutputSafety:
48
+ Exclude:
49
+ - 'app/controllers/hyrax/iiif_av/iiif_av_controller.rb'
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,181 @@
1
+ # How to Contribute
2
+
3
+ We want your help to make the Samvera community great. There are a few guidelines
4
+ that we need contributors to follow so that we can have a chance of
5
+ keeping on top of things.
6
+
7
+ ## Code of Conduct
8
+
9
+ The Samvera Community is dedicated to providing a welcoming and positive
10
+ experience for all its members, whether they are at a formal gathering, in
11
+ a social setting, or taking part in activities online. Please see our
12
+ [Code of Conduct](CODE_OF_CONDUCT.md) for more information.
13
+
14
+ ## Language
15
+
16
+ The language we use matters. Today, tomorrow, and for years to come
17
+ people will read the code we write. They will judge us for our
18
+ design, logic, and the words we use to describe the system.
19
+
20
+ Our words should be accessible. Favor descriptive words that give
21
+ meaning while avoiding reinforcing systemic inequities. For example,
22
+ in the Samvera community, we should favor using allowed_list instead
23
+ of whitelist, denied_list instead of blacklist, or source/copy
24
+ instead of master/slave.
25
+
26
+ We're going to get it wrong, but this is a call to keep working to
27
+ make it right. View our code and the words we choose as a chance to
28
+ have a conversation. A chance to grow an understanding of the systems
29
+ we develop as well as the systems in which we live.
30
+
31
+ See [“Blacklists” and “whitelists”: a salutary warning concerning the
32
+ prevalence of racist language in discussions of predatory
33
+ publishing](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC6148600/) for
34
+ further details.
35
+
36
+ ## Contribution Tasks
37
+
38
+ - Reporting Issues
39
+ - Making Changes
40
+ - Documenting Code
41
+ - Committing Changes
42
+ - Submitting Changes
43
+ - Reviewing and Merging Changes
44
+
45
+ ### Reporting Issues
46
+
47
+ - Make sure you have a [GitHub account](https://github.com/signup/free)
48
+ - Submit a [Github issue](https://github.com/samvera-labs/hyrax-iiif_av/issues/) by:
49
+ - Clearly describing the issue
50
+ - Provide a descriptive summary
51
+ - Explain the expected behavior
52
+ - Explain the actual behavior
53
+ - Provide steps to reproduce the actual behavior
54
+
55
+ ### Making Changes
56
+
57
+ - Fork the repository on GitHub
58
+ - Create a topic branch from where you want to base your work.
59
+ - This is usually the `main` branch.
60
+ - To quickly create a topic branch based on `main`; `git branch fix/main/my_contribution main`
61
+ - Then checkout the new branch with `git checkout fix/main/my_contribution`.
62
+ - Please avoid working directly on the `main` branch.
63
+ - Please do not create a branch called `master`. (See note below.)
64
+ - You may find the [hub suite of commands](https://github.com/defunkt/hub) helpful
65
+ - Make sure you have added sufficient tests and documentation for your changes.
66
+ - Test functionality with RSpec; Test features / UI with Capybara.
67
+ - Run _all_ the tests to assure nothing else was accidentally broken.
68
+
69
+ NOTE: This repository follows the [Samvera Community Code of Conduct](https://samvera.atlassian.net/wiki/spaces/samvera/pages/405212316/Code+of+Conduct)
70
+ and [language recommendations](#language).
71
+ Please **_do not_** create a branch called `master` for this repository or as part of
72
+ your pull request; the branch will either need to be removed or renamed before it can
73
+ be considered for inclusion in the code base and history of this repository.
74
+
75
+ ### Documenting Code
76
+
77
+ - All new public methods, modules, and classes should include inline documentation in [YARD](http://yardoc.org/).
78
+ - Documentation should seek to answer the question "why does this code exist?"
79
+ - Document private / protected methods as desired.
80
+ - If you are working in a file with no prior documentation, do try to document as you gain understanding of the code.
81
+ - If you don't know exactly what a bit of code does, it is extra likely that it needs to be documented. Take a stab at it and ask for feedback in your pull request. You can use the 'blame' button on GitHub to identify the original developer of the code and @mention them in your comment.
82
+ - This work greatly increases the usability of the code base and supports the on-ramping of new committers.
83
+ - We will all be understanding of one another's time constraints in this area.
84
+ - [Getting started with YARD](http://www.rubydoc.info/gems/yard/file/docs/GettingStarted.md)
85
+
86
+ ### Committing changes
87
+
88
+ - Make commits of logical units.
89
+ - Check for unnecessary whitespace with `git diff --check` before committing.
90
+ - Make sure your commit messages are [well formed](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
91
+ - If you created an issue, you can close it by including "Closes #issue" in your commit message. See [Github's blog post for more details](https://github.com/blog/1386-closing-issues-via-commit-messages)
92
+
93
+ ```
94
+ Present tense short summary (50 characters or less)
95
+
96
+ More detailed description, if necessary. It should be wrapped to 72
97
+ characters. Try to be as descriptive as you can, even if you think that
98
+ the commit content is obvious, it may not be obvious to others. You
99
+ should add such description also if it's already present in bug tracker,
100
+ it should not be necessary to visit a webpage to check the history.
101
+
102
+ Include Closes #<issue-number> when relavent.
103
+
104
+ Description can have multiple paragraphs and you can use code examples
105
+ inside, just indent it with 4 spaces:
106
+
107
+ class PostsController
108
+ def index
109
+ respond_to do |wants|
110
+ wants.html { render 'index' }
111
+ end
112
+ end
113
+ end
114
+
115
+ You can also add bullet points:
116
+
117
+ - you can use dashes or asterisks
118
+
119
+ - also, try to indent next line of a point for readability, if it's too
120
+ long to fit in 72 characters
121
+ ```
122
+
123
+ - Make sure you have added the necessary tests for your changes.
124
+ - Run _all_ the tests to assure nothing else was accidentally broken.
125
+ - When you are ready to submit a pull request
126
+
127
+ ### Submitting Changes
128
+
129
+ - Read the article ["Using Pull Requests"](https://help.github.com/articles/using-pull-requests) on GitHub.
130
+ - Make sure your branch is up to date with its parent branch (i.e. main)
131
+ - `git checkout main`
132
+ - `git pull --rebase`
133
+ - `git checkout <your-branch>`
134
+ - `git rebase main`
135
+ - It is a good idea to run your tests again.
136
+ - If you've made more than one commit take a moment to consider whether squashing commits together would help improve their logical grouping.
137
+ - [Detailed Walkthrough of One Pull Request per Commit](http://ndlib.github.io/practices/one-commit-per-pull-request/)
138
+ - `git rebase --interactive main` ([See Github help](https://help.github.com/articles/interactive-rebase))
139
+ - Squashing your branch's changes into one commit is "good form" and helps the person merging your request to see everything that is going on.
140
+ - Push your changes to a topic branch in your fork of the repository.
141
+ - Submit a pull request from your fork to the project.
142
+
143
+ ### Reviewing and Merging Changes
144
+
145
+ We adopted [Github's Pull Request Review](https://help.github.com/articles/about-pull-request-reviews/) for our repositories.
146
+ Common checks that may occur in our repositories:
147
+
148
+ 1. [CircleCI](https://circleci.com/gh/samvera) - where our automated tests are running
149
+ 2. RuboCop/Bixby - where we check for style violations
150
+ 3. Approval Required - Github enforces at least one person approve a pull request. Also, all reviewers that have chimed in must approve.
151
+ 4. CodeClimate - is our code remaining healthy (at least according to static code analysis)
152
+
153
+ If one or more of the required checks failed (or are incomplete), the code should not be merged (and the UI will not allow it). If all of the checks have passed, then anyone on the project (including the pull request submitter) may merge the code.
154
+
155
+ _Example: Carolyn submits a pull request, Justin reviews the pull request and approves. However, Justin is still waiting on other checks (CI tests are usually the culprit), so he does not merge the pull request. Eventually, all of the checks pass. At this point, Carolyn or anyone else may merge the pull request._
156
+
157
+ #### Things to Consider When Reviewing
158
+
159
+ First, the person contributing the code is putting themselves out there. Be mindful of what you say in a review.
160
+
161
+ - Ask clarifying questions
162
+ - State your understanding and expectations
163
+ - Provide example code or alternate solutions, and explain why
164
+
165
+ This is your chance for a mentoring moment of another developer. Take time to give an honest and thorough review of what has changed. Things to consider:
166
+
167
+ - Does the commit message explain what is going on?
168
+ - Does the code changes have tests? _Not all changes need new tests, some changes are refactorings_
169
+ - Do new or changed methods, modules, and classes have documentation?
170
+ - Does the commit contain more than it should? Are two separate concerns being addressed in one commit?
171
+ - Does the description of the new/changed specs match your understanding of what the spec is doing?
172
+ - Did the Continuous Integration tests complete successfully?
173
+
174
+ If you are uncertain, bring other contributors into the conversation by assigning them as a reviewer.
175
+
176
+ # Additional Resources
177
+
178
+ - [General GitHub documentation](http://help.github.com/)
179
+ - [GitHub pull request documentation](https://help.github.com/articles/about-pull-requests/)
180
+ - [Pro Git](http://git-scm.com/book) is both a free and excellent book about Git.
181
+ - [A Git Config for Contributing](http://ndlib.github.io/practices/my-typical-per-project-git-config/)
data/README.md CHANGED
@@ -1,43 +1,40 @@
1
1
  # hyrax-iiif_av
2
2
  Hyrax plugin for IIIF Presentation 3.0 Audiovisual support
3
3
 
4
- # Steps to use this plugin
5
- 1. Include controller mixin in your model controller:
6
- ```ruby
7
- # Generated via
8
- # `rails generate hyrax:work GenericWork`
9
- module Hyrax
10
- # Generated controller for GenericWork
11
- class GenericWorksController < ApplicationController
12
- # Adds Hyrax behaviors to the controller.
13
- include Hyrax::WorksControllerBehavior
14
- include Hyrax::BreadcrumbsForWorks
15
- include Hyrax::IiifAv::ControllerBehavior
16
- self.curation_concern_type = ::GenericWork
17
-
18
- # Use this line if you want to use a custom presenter
19
- self.show_presenter = Hyrax::GenericWorkPresenter
20
- end
21
- end
4
+ # How to use this plugin
5
+ 1. Add `hyrax-iiif_av` to your `Gemfile` and `bundle install`
6
+
7
+ 2. Run generator passing your work type:
8
+ ```
9
+ rails g hyrax:iiif_av:add_to_work_type MyWorkType
22
10
  ```
11
+ Notice that this generator includes mixins in the work controller and work show presenter.
23
12
 
24
- 2. Setup work presenter:
25
- ```ruby
26
- # Generated via
27
- # `rails generate hyrax:work GenericWork`
28
- module Hyrax
29
- class GenericWorkPresenter < Hyrax::WorkShowPresenter
30
- include Hyrax::IiifAv::DisplaysIiifAv
31
-
32
- Hyrax::MemberPresenterFactory.file_presenter_class = Hyrax::IiifAv::IiifFileSetPresenter
33
-
34
- # Optional override to select iiif viewer to render
35
- # default :avalon for AV, :universal_viewer for images
36
- def iiif_viewer
37
- :universal_viewer
38
- end
39
- end
40
- end
13
+ 3. (Optional) Run avalon player generator:
41
14
  ```
15
+ rails g hyrax:iiif_av:install_avalon_player
16
+ ```
17
+ This will install `webpacker`, `react-rails`, and the avalon player (view partial, react JS, and yarn dependency). This might take a while.
18
+
19
+ 4. Ingest audiovisual content and see a IIIF viewer render on the work show page.
20
+
21
+ For a walkthrough of this in a demo application try running through this repository's README: https://github.com/avalonmediasystem/connect2018-workshop
22
+
23
+
24
+ # Set up dev / test environment
25
+ This project uses engine cart for testing and development purposes. To generate the .internal_test_app directory do the following
26
+
27
+ ```bash
28
+ export ENGINE_CART_RAILS_OPTIONS="--skip-git --skip-bundle --skip-listen --skip-spring --skip-yarn --skip-keeps --skip-coffee --skip-puma --skip-test"
29
+ bundle exec rake engine_cart:generate
30
+ ```
31
+
32
+ Spec and rubocop can then be run using the `rake` command.
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/samvera-labs/hyrax-iiif_av>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
37
+
38
+ If you're working on PR for this project, create a feature branch off of `main`.
42
39
 
43
- 3. Ingest audiovisual content and see the Avalon IIIF viewer render on the work show page.
40
+ This repository follows the [Samvera Community Code of Conduct](https://samvera.atlassian.net/wiki/spaces/samvera/pages/405212316/Code+of+Conduct) and [language recommendations](https://github.com/samvera-labs/hyrax-iiif_av/blob/main/CONTRIBUTING.md#language). Please ***do not*** create a branch called `master` for this repository or as part of your pull request; the branch will either need to be removed or renamed before it can be considered for inclusion in the code base and history of this repository.
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2011-2018, The Trustees of Indiana University and Northwestern
4
+ # University. Additional copyright may be held by others, as reflected in
5
+ # the commit history.
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ # --- END LICENSE_HEADER BLOCK ---
19
+
20
+ module Hyrax
21
+ module IiifAv
22
+ module AuthControllerBehavior
23
+ extend ActiveSupport::Concern
24
+
25
+ def after_sign_in_path_for(resource_or_scope)
26
+ return Hyrax::IiifAv::Engine.routes.url_helpers.iiif_av_sign_in_path if referer_iiif_login? || request_iiif_login?
27
+ super
28
+ end
29
+
30
+ private
31
+
32
+ def referer_iiif_login?
33
+ # When going through the login form
34
+ referer_uri_string = request.env.fetch("HTTP_REFERER", nil)
35
+ return false unless referer_uri_string.present?
36
+ referer_uri = URI(referer_uri_string)
37
+ # Don't worry about referers that come from a different site (includings where the IIIF viewer is embedded)
38
+ return false if referer_uri.host.present? && referer_uri.host != request.host
39
+ query_params = Rack::Utils.parse_query(referer_uri.query)
40
+ query_params && ActiveModel::Type::Boolean.new.cast(query_params["iiif_auth_login"])
41
+ end
42
+
43
+ def request_iiif_login?
44
+ # When already logged in
45
+ request_uri_string = request.env.fetch("REQUEST_URI", nil)
46
+ return false unless request_uri_string.present?
47
+ request_uri = URI(request_uri_string)
48
+ query_params = Rack::Utils.parse_query(request_uri.query)
49
+ ActiveModel::Type::Boolean.new.cast(query_params["iiif_auth_login"])
50
+ end
51
+ end
52
+ end
53
+ end
@@ -24,22 +24,29 @@ module Hyrax
24
24
 
25
25
  included do
26
26
  prepend_view_path(Hyrax::IiifAv::Engine.view_path)
27
- helper Hyrax::IiifAv::IiifAvHelper
28
27
  end
29
28
 
30
- IIIF_PRESENTATION_2_MIME = 'application/json;profile=http://iiif.io/api/presentation/2/context.json'
31
- IIIF_PRESENTATION_3_MIME = 'application/json;profile=http://iiif.io/api/presentation/3/context.json'
29
+ IIIF_PRESENTATION_2_MIME = 'application/ld+json;profile="http://iiif.io/api/presentation/2/context.json"'
30
+ IIIF_PRESENTATION_3_MIME = 'application/ld+json;profile="http://iiif.io/api/presentation/3/context.json"'
32
31
 
33
32
  def manifest
34
33
  add_iiif_header
35
- super
34
+
35
+ headers['Access-Control-Allow-Origin'] = '*'
36
+
37
+ json = iiif_manifest_builder.manifest_for(presenter: iiif_manifest_presenter, iiif_manifest_factory: manifest_factory)
38
+
39
+ respond_to do |wants|
40
+ wants.json { render json: json }
41
+ wants.html { render json: json }
42
+ end
36
43
  end
37
44
 
38
45
  private
39
46
 
40
47
  # @return true if the request is for IIIF version 3; false otherwise
41
48
  def iiif_version_3?
42
- presenter.respond_to?(:iiif_version) ? presenter.iiif_version == 3 : false
49
+ iiif_manifest_presenter.respond_to?(:iiif_version) ? iiif_manifest_presenter.iiif_version == 3 : false
43
50
  end
44
51
 
45
52
  def iiif_mime
@@ -51,11 +58,19 @@ module Hyrax
51
58
  headers['Content-Type'] = iiif_mime
52
59
  end
53
60
 
54
- def manifest_builder
61
+ # Override this method to return classes instead of instances
62
+ # This forces the manifest action to call Hyrax::ManifestBuilderService.manifest_for
63
+ # which allows for the passing in of the manifest factory
64
+ def iiif_manifest_builder
65
+ self.class.iiif_manifest_builder ||
66
+ (Flipflop.cache_work_iiif_manifest? ? Hyrax::CachingIiifManifestBuilder : Hyrax::ManifestBuilderService)
67
+ end
68
+
69
+ def manifest_factory
55
70
  if iiif_version_3?
56
- ::IIIFManifest::V3::ManifestFactory.new(presenter)
71
+ ::IIIFManifest::V3::ManifestFactory
57
72
  else
58
- ::IIIFManifest::ManifestFactory.new(presenter)
73
+ ::IIIFManifest::ManifestFactory
59
74
  end
60
75
  end
61
76
  end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module IiifAv
4
+ class IiifAvController < ApplicationController
5
+ include Blacklight::Base
6
+ include Blacklight::AccessControls::Catalog
7
+
8
+ def content
9
+ file_set_id = params[:id]
10
+ label = params[:label]
11
+ if request.head?
12
+ return head :ok if valid_token? || can?(:read, params[:id])
13
+ return head :unauthorized
14
+ else
15
+ return head :unauthorized unless presenter
16
+ return redirect_to hyrax.download_path(file_set_id, file: label, locale: nil) unless stream_urls[label]
17
+ redirect_to stream_urls[label]
18
+ end
19
+ end
20
+
21
+ def auth_token
22
+ return head :unauthorized unless can? :read, params[:id]
23
+ response.set_header('Content-Security-Policy', 'frame-ancestors *')
24
+ render html: auth_token_html_response(generate_auth_token)
25
+ end
26
+
27
+ # This route is meant to be used with devise's `after_sign_in_path_for` as part of the IIIF Auth flow
28
+ # See the override of `after_sign_in_path_for` in Hyrax::IiifAv::AuthControllerBehavior
29
+ def sign_in
30
+ render inline: "<html><head><script>window.close();</script></head><body></body></html>".html_safe
31
+ end
32
+
33
+ private
34
+
35
+ def generate_auth_token
36
+ # This is the same method used by ActiveRecord::SecureToken
37
+ token = SecureRandom.base58(24)
38
+ Rails.cache.write("iiif_auth_token-#{token}", params[:id])
39
+ token
40
+ end
41
+
42
+ def auth_token_html_response(token)
43
+ message = { messageId: params[:messageId], accessToken: token }
44
+ origin = Rails::Html::FullSanitizer.new.sanitize(params[:origin])
45
+ "<html><body><script>window.parent.postMessage(#{message.to_json}, \"#{origin}\");</script></body></html>".html_safe
46
+ end
47
+
48
+ def valid_token?
49
+ auth_token = request.headers['Authorization']&.sub('Bearer ', '')&.strip
50
+ resource_id = Rails.cache.read("iiif_auth_token-#{auth_token}")
51
+ params[:id] == resource_id
52
+ end
53
+
54
+ # Override of Blacklight::RequestBuilders
55
+ def search_builder_class
56
+ Hyrax::FileSetSearchBuilder
57
+ end
58
+
59
+ def presenter
60
+ @presenter ||= begin
61
+ _, document_list = search_results(params)
62
+ curation_concern = document_list.first
63
+ return nil unless curation_concern
64
+ # Use the show presenter configured in the FileSetsController
65
+ Hyrax::FileSetsController.show_presenter.new(curation_concern, current_ability, request)
66
+ end
67
+ end
68
+
69
+ # Duplicated here from Hyrax::IiifAv::DisplaysContent
70
+ def stream_urls
71
+ @stream_urls ||= begin
72
+ return {} unless presenter.solr_document['derivatives_metadata_ssi'].present?
73
+ files_metadata = JSON.parse(presenter.solr_document['derivatives_metadata_ssi'])
74
+ file_locations = files_metadata.select { |f| f['file_location_uri'].present? }
75
+ return {} unless file_locations.present?
76
+ streams = {}
77
+ file_locations.each do |f|
78
+ streams[f['label']] = Hyrax::IiifAv.config.iiif_av_url_builder.call(
79
+ f['file_location_uri'],
80
+ request.base_url
81
+ )
82
+ end
83
+ streams
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end