diff --git a/Gemfile b/Gemfile index 9db1cc92..d7057efa 100644 --- a/Gemfile +++ b/Gemfile @@ -73,7 +73,7 @@ gem 'http' gem 'cancancan' gem 'dalli' gem 'retries' -gem 'zipline', '~> 2.0' +gem 'zip_kit', '~> 6.3' gem 'jwt' gem 'redis' diff --git a/Gemfile.lock b/Gemfile.lock index f839fe0a..29aa3185 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -124,7 +124,6 @@ GEM deep_merge (~> 1.2, >= 1.2.1) ostruct connection_pool (2.4.1) - content_disposition (1.0.0) crack (1.0.0) bigdecimal rexml @@ -397,10 +396,6 @@ GEM nokogiri (~> 1.8) zeitwerk (2.7.1) zip_kit (6.3.1) - zipline (2.0.0) - actionpack (>= 6.0, < 8.0) - content_disposition (~> 1.0) - zip_kit (~> 6, >= 6.2.0, < 7) PLATFORMS arm64-darwin-23 @@ -449,7 +444,7 @@ DEPENDENCIES web-console (>= 4.1.0) webdrivers webmock (~> 3.0) - zipline (~> 2.0) + zip_kit (~> 6.3) BUNDLED WITH 2.5.14 diff --git a/app/controllers/object_controller.rb b/app/controllers/object_controller.rb index 515dd91e..2c20d48d 100644 --- a/app/controllers/object_controller.rb +++ b/app/controllers/object_controller.rb @@ -3,8 +3,6 @@ ## # API for delivering whole objects from stacks class ObjectController < ApplicationController - include Zipline - # Return a zip of all the files if they have access to all the files. # This will force a login if any of the files is not access=world def show @@ -15,25 +13,28 @@ def show files.each do |file| authorize! :download, file end - zip_contents = files.map do |file| - [ - file, - file.file_name, - modification_time: file.mtime - ] + + track_download + + zip_kit_stream(filename: "#{druid}.zip") do |zip| + files.each do |stacks_file| + zip.write_file(stacks_file.file_name, modification_time: stacks_file.mtime) do |sink| + File.open(stacks_file.path, "rb") { |file_input| IO.copy_stream(file_input, sink) } + end + end end + end + private + + def track_download TrackDownloadJob.perform_later( druid:, user_agent: request.user_agent, ip: request.remote_ip ) - - zipline(zip_contents, "#{druid}.zip") end - private - def druid params[:id] end diff --git a/app/models/cocina.rb b/app/models/cocina.rb index e56c49bb..54597fd7 100644 --- a/app/models/cocina.rb +++ b/app/models/cocina.rb @@ -6,6 +6,7 @@ class Cocina THUMBNAIL_MIME_TYPE = 'image/jp2' + # @return [Cocina] Returns the cocina object for the given druid and version def self.find(druid, version = :head) data = Rails.cache.fetch(metadata_cache_key(druid, version), expires_in: 10.minutes) do benchmark "Fetching public json for #{druid} version #{version}" do @@ -73,6 +74,7 @@ def embargo_release_date data.dig('access', 'embargo', 'releaseDate') end + # @return [Enumerator] when no block is passed def files(&) return to_enum(:files) unless block_given?