Class: Shrine::Plugins::KitheAcceptRemoteUrl
- Inherits:
-
Object
- Object
- Shrine::Plugins::KitheAcceptRemoteUrl
- Defined in:
- lib/shrine/plugins/kithe_accept_remote_url.rb
Overview
This plugin supports assigning remote URLs to shrine attachments, in uploaders that have normal default cache storage.
It also supports specifying custom request headers for those remote URLs, to support OAuth2 Authorization headers, with browse-everything or similar.
It uses the shrine-url storage, registering it as storage with key “remote_url”; our custom kithe_multi_cache plugin to allow this alternate storage to be set as cache even though it’s not main cache; and a #promote override suggested by Janko@shrine to get request headers to be supported.
Testing is done in context of Asset model, see asset_spec.rb.
FUTURE. Need to whitelist allowed URLs/hostnames. :( A pain cause it’ll be different for different apps, so we need to allow uploader customization?
Defined Under Namespace
Modules: AttacherMethods
Class Method Summary collapse
Class Method Details
.configure(uploader, options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/shrine/plugins/kithe_accept_remote_url.rb', line 21 def self.configure(uploader, = {}) # Ensure remote_url is registered as a storage # Note, using downloader: :net_http so it can be tested with WebMock, would be # better not to have to do that. # https://github.com/shrinerb/shrine-url/issues/5 # # Lazy default to make it easier to specify other. uploader.storages[:remote_url] ||= Shrine::Storage::Url.new end |
.load_dependencies(uploader) ⇒ Object
31 32 33 34 35 |
# File 'lib/shrine/plugins/kithe_accept_remote_url.rb', line 31 def self.load_dependencies(uploader, *) # Make sure the uploader will accept assignments/promotion from remote_url, using # our multi_cache plugin. uploader.plugin :kithe_multi_cache, additional_cache: :remote_url end |