Skip to content

Commit

Permalink
Merge pull request #24 from performant-software/feature/iiif23_upload
Browse files Browse the repository at this point in the history
IIIF #23 - Upload issue
  • Loading branch information
dleadbetter authored Nov 18, 2022
2 parents 2f567fd + b1fe6bc commit ba9c9c7
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
web: bundle exec puma -C config/puma.rb
release: bin/rake db:migrate:with_data
worker: bundle exec sidekiq -q default
worker: bundle exec sidekiq -e production -C config/sidekiq.yml
25 changes: 15 additions & 10 deletions app/services/iiif/manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ def self.create(resource)
en: [resource.name]
}

info = resource_info(resource)

page_count = info['page_count'] || 1
width = info['width']
height = info['height']

items = []

page_count(resource).times do |index|
items << create_canvas(resource, index + 1)
page_count.times do |index|
items << create_canvas(resource, width, height, index + 1)
end

manifest['items'] = items
Expand Down Expand Up @@ -54,9 +60,11 @@ def self.create_annotation(resource, target, page_number)
annotation
end

def self.create_canvas(resource, page_number)
def self.create_canvas(resource, width, height, page_number)
canvas = to_json('canvas.json')
canvas['id'] = "https://#{resource.uuid}/canvas/#{page_number}"
canvas['width'] = width
canvas['height'] = height

canvas['items'] = [{
id: "https://#{resource.uuid}/canvas/#{page_number}/annotation_page/1",
Expand All @@ -67,18 +75,15 @@ def self.create_canvas(resource, page_number)
canvas
end

def self.page_count(resource)
page_count = 1

def self.resource_info(resource)
begin
response = HTTParty.get("#{resource.content_base_url}/info.json")
context = JSON.parse(response.body)
page_count = context['page_count'] || 1
info = JSON.parse(response.body)
rescue
# Do nothing. There's a possibility there may be no response from the server.
info = {}
end

page_count
info
end

def self.to_json(filename)
Expand Down
2 changes: 1 addition & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
default: &default
adapter: postgresql
timeout: 5000
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 10 } %>
pool: <%= ENV.fetch('RAILS_MAX_THREADS') { 5 } %>
host: <%= ENV.fetch('DATABASE_HOST') { 'localhost' } %>
port: <%= ENV.fetch('DATABASE_POST') { 5432 } %>
username: <%= ENV.fetch('DATABASE_USERNAME') { '' } %>
Expand Down
3 changes: 3 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :amazon

# Use MiniMagick as the variant processor
config.active_storage.variant_processor = :mini_magick

# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false

Expand Down
3 changes: 3 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :amazon

# Use MiniMagick as the variant processor
config.active_storage.variant_processor = :mini_magick

# Mount Action Cable outside main process or domain.
# config.action_cable.mount_path = nil
# config.action_cable.url = "wss://example.com/cable"
Expand Down
9 changes: 9 additions & 0 deletions config/initializers/sidekiq.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
if Rails.env.production?
Sidekiq.configure_server do |config|
config.redis = { ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE } }
end

Sidekiq.configure_client do |config|
config.redis = { ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE } }
end
end
6 changes: 6 additions & 0 deletions config/sidekiq.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
development:
:concurrency: <%= ENV.fetch("SIDEKIQ_CONCURRENCY") { 5 } %>
production:
:concurrency: <%= ENV.fetch("SIDEKIQ_CONCURRENCY") { 5 } %>
:queues:
- default

0 comments on commit ba9c9c7

Please sign in to comment.