Browse Source
* Refactor collection resources to use storage service * Add a feature flag * Update tests * Update stubspull/2658/head^2
kosiakkatrina
3 months ago
committed by
GitHub
20 changed files with 46 additions and 46 deletions
@ -1,33 +1,21 @@
|
||||
class CollectionResourcesService |
||||
def initialize |
||||
@storage_service = Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["COLLECTION_RESOURCES_BUCKET"]) |
||||
@storage_service = if FeatureToggle.local_storage? |
||||
Storage::LocalDiskService.new |
||||
else |
||||
Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["COLLECTION_RESOURCES_BUCKET"]) |
||||
end |
||||
|
||||
def get_file(file) |
||||
storage_service = Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["COLLECTION_RESOURCES_BUCKET"]) |
||||
url = "https://#{storage_service.configuration.bucket_name}.s3.amazonaws.com/#{file}" |
||||
uri = URI.parse(url) |
||||
|
||||
response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http| |
||||
request = Net::HTTP::Get.new(uri) |
||||
http.request(request) |
||||
end |
||||
|
||||
return unless response.is_a?(Net::HTTPSuccess) |
||||
|
||||
response.body |
||||
def get_file(file) |
||||
@storage_service.get_file_io(file) |
||||
rescue StandardError |
||||
nil |
||||
end |
||||
|
||||
def get_file_metadata(file) |
||||
storage_service = Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["COLLECTION_RESOURCES_BUCKET"]) |
||||
url = "https://#{storage_service.configuration.bucket_name}.s3.amazonaws.com/#{file}" |
||||
uri = URI.parse(url) |
||||
|
||||
response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http| |
||||
http.request_head(uri) |
||||
end |
||||
return unless response.is_a?(Net::HTTPSuccess) || response.is_a?(Net::HTTPRedirection) |
||||
|
||||
response |
||||
@storage_service.get_file_metadata(file) |
||||
rescue StandardError |
||||
nil |
||||
end |
||||
end |
||||
|
Loading…
Reference in new issue