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 |
class CollectionResourcesService |
||||||
def initialize |
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 |
||||||
end |
end |
||||||
|
|
||||||
def get_file(file) |
def get_file(file) |
||||||
storage_service = Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["COLLECTION_RESOURCES_BUCKET"]) |
@storage_service.get_file_io(file) |
||||||
url = "https://#{storage_service.configuration.bucket_name}.s3.amazonaws.com/#{file}" |
rescue StandardError |
||||||
uri = URI.parse(url) |
nil |
||||||
|
|
||||||
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 |
|
||||||
end |
end |
||||||
|
|
||||||
def get_file_metadata(file) |
def get_file_metadata(file) |
||||||
storage_service = Storage::S3Service.new(Configuration::EnvConfigurationService.new, ENV["COLLECTION_RESOURCES_BUCKET"]) |
@storage_service.get_file_metadata(file) |
||||||
url = "https://#{storage_service.configuration.bucket_name}.s3.amazonaws.com/#{file}" |
rescue StandardError |
||||||
uri = URI.parse(url) |
nil |
||||||
|
|
||||||
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 |
|
||||||
end |
end |
||||||
end |
end |
||||||
|
Loading…
Reference in new issue