Proxy for active storage service provider
This commit is contained in:
parent
5e9b6bd850
commit
0846860748
4 changed files with 76 additions and 1 deletions
34
app/lib/active_storage/service/ds_proxy_service.rb
Normal file
34
app/lib/active_storage/service/ds_proxy_service.rb
Normal file
|
@ -0,0 +1,34 @@
|
|||
module ActiveStorage
|
||||
# Wraps an ActiveStorage::Service to route direct upload and direct download URLs through our proxy,
|
||||
# thus avoiding exposing the storage provider’s URL to our end-users.
|
||||
class Service::DsProxyService < SimpleDelegator
|
||||
attr_reader :wrapped
|
||||
|
||||
def self.build(wrapped:, configurator:, **options)
|
||||
new(wrapped: configurator.build(wrapped))
|
||||
end
|
||||
|
||||
def initialize(wrapped:)
|
||||
@wrapped = wrapped
|
||||
super(wrapped)
|
||||
end
|
||||
|
||||
def url(*args)
|
||||
url = wrapped.url(*args)
|
||||
publicize(url)
|
||||
end
|
||||
|
||||
def url_for_direct_upload(*args)
|
||||
url = wrapped.url_for_direct_upload(*args)
|
||||
publicize(url)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def publicize(url)
|
||||
search = %r{^https://[^/]+/v1/AUTH_[a-f0-9]{32}}
|
||||
replace = 'https://static.demarches-simplifiees.fr'
|
||||
url.gsub(search, replace)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue