Skip to content

Commit

Permalink
🐛 Override BrowseEverything for S3 file size
Browse files Browse the repository at this point in the history
This commit will bring in an override for the BrowseEverything gem to
retrieve the file size from an S3 object and pass it into the params so
that the Bulkrax importer can use it.
  • Loading branch information
kirkkwang committed Mar 25, 2024
1 parent ad5354d commit d888ca9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class Application < Rails::Application
Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")).sort.each do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end

Dir.glob(File.join(File.dirname(__FILE__), "../lib/**/*_decorator*.rb")).sort.each do |c|
Rails.configuration.cache_classes ? require(c) : load(c)
end
end

# resolve reloading issue in dev mode
Expand Down
31 changes: 31 additions & 0 deletions lib/browse_everything/driver/s3_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

# OVERRIDE BrowseEverything v1.1.2 to add file_size for S3 files

module BrowseEverything
module Driver
module S3Decorator
def link_for(path)
obj = bucket.object(full_path(path))
obj_head = obj.head
file_size = obj_head.content_length

extras = {
file_name: File.basename(path),
file_size: file_size,
expires: (config[:expires_in] if config[:response_type] == :signed_url)
}.compact

url = case config[:response_type].to_sym
when :signed_url then obj.presigned_url(:get, expires_in: config[:expires_in])
when :public_url then obj.public_url
when :s3_uri then "s3://#{obj.bucket_name}/#{obj.key}"
end

[url, extras]
end
end
end
end

BrowseEverything::Driver::S3.prepend(BrowseEverything::Driver::S3Decorator)

0 comments on commit d888ca9

Please sign in to comment.