diff --git a/config/application.rb b/config/application.rb index 81e96553..aec03e85 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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 diff --git a/config/browse_everything_providers.yml b/config/browse_everything_providers.yml index 9fefd0a8..f6e818cd 100644 --- a/config/browse_everything_providers.yml +++ b/config/browse_everything_providers.yml @@ -2,8 +2,8 @@ # To make browse-everything aware of a provider, uncomment the info for that provider and add your API key information. # The file_system provider can be a path to any directory on the server where your application is running. # -file_system: - home: /app/samvera/hyrax-webapp/data +#file_system: +# home: /app/samvera/hyrax-webapp/data # dropbox: # client_id: YOUR_DROPBOX_APP_KEY # client_secret: YOUR_DROPBOX_APP_SECRET @@ -14,11 +14,11 @@ file_system: # google_drive: # client_id: YOUR_GOOGLE_API_CLIENT_ID # client_secret: YOUR_GOOGLE_API_CLIENT_SECRET -# s3: -# bucket: YOUR_AWS_S3_BUCKET -# response_type: signed_url # set to :public_url for public urls or :s3_uri for an s3://BUCKET/KEY uri -# expires_in: 14400 # for signed_url response_type, number of seconds url will be valid for. -# app_key: YOUR_AWS_S3_KEY # :app_key, :app_secret, and :region can be specified -# app_secret: YOUR_AWS_S3_SECRET # explicitly here, or left out to use system-configured -# region: YOUR_AWS_S3_REGION # defaults. -# See https://aws.amazon.com/blogs/security/a-new-and-standardized-way-to-manage-credentials-in-the-aws-sdks/ +s3: + bucket: temp-bl-bucket-for-browse-everything # .s3.amazonaws.com #arn:aws:s3:::temp-bl-bucket-for-browse-everything + response_type: signed_url # set to :public_url for public urls or :s3_uri for an s3://BUCKET/KEY uri + expires_in: 14400 # for signed_url response_type, number of seconds url will be valid for. + app_key: <%= ENV['AWS_ACCESS_KEY_ID'] %> # :app_key, :app_secret, and :region can be specified + app_secret: <%= ENV['AWS_SECRET_ACCESS_KEY'] %> # explicitly here, or left out to use system-configured + region: eu-west-1 # defaults. + # See https://aws.amazon.com/blogs/security/a-new-and-standardized-way-to-manage-credentials-in-the-aws-sdks/ diff --git a/lib/browse_everything/driver/s3_decorator.rb b/lib/browse_everything/driver/s3_decorator.rb new file mode 100644 index 00000000..9f73b348 --- /dev/null +++ b/lib/browse_everything/driver/s3_decorator.rb @@ -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)