diff options
Diffstat (limited to 'activestorage/lib/active_storage/service.rb')
-rw-r--r-- | activestorage/lib/active_storage/service.rb | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/activestorage/lib/active_storage/service.rb b/activestorage/lib/active_storage/service.rb index ce736b8728..f2e1269f27 100644 --- a/activestorage/lib/active_storage/service.rb +++ b/activestorage/lib/active_storage/service.rb @@ -4,6 +4,7 @@ require "active_storage/log_subscriber" module ActiveStorage class IntegrityError < StandardError; end + # Abstract class serving as an interface for concrete services. # # The available services are: @@ -40,7 +41,7 @@ module ActiveStorage extend ActiveSupport::Autoload autoload :Configurator - class_attribute :logger + class_attribute :url_expires_in, default: 5.minutes class << self # Configure an Active Storage service by name from a set of configurations, @@ -77,7 +78,12 @@ module ActiveStorage raise NotImplementedError end - # Return true if a file exists at the +key+. + # Delete files at keys starting with the +prefix+. + def delete_prefixed(prefix) + raise NotImplementedError + end + + # Return +true+ if a file exists at the +key+. def exist?(key) raise NotImplementedError end @@ -91,7 +97,7 @@ module ActiveStorage # Returns a signed, temporary URL that a direct upload file can be PUT to on the +key+. # The URL will be valid for the amount of seconds specified in +expires_in+. - # You most also provide the +content_type+, +content_length+, and +checksum+ of the file + # You must also provide the +content_type+, +content_length+, and +checksum+ of the file # that will be uploaded. All these attributes will be validated by the service upon upload. def url_for_direct_upload(key, expires_in:, content_type:, content_length:, checksum:) raise NotImplementedError @@ -103,15 +109,19 @@ module ActiveStorage end private - def instrument(operation, key, payload = {}, &block) + def instrument(operation, payload = {}, &block) ActiveSupport::Notifications.instrument( "service_#{operation}.active_storage", - payload.merge(key: key, service: service_name), &block) + payload.merge(service: service_name), &block) end def service_name # ActiveStorage::Service::DiskService => Disk self.class.name.split("::").third.remove("Service") end + + def content_disposition_with(type: "inline", filename:) + (type.to_s.presence_in(%w( attachment inline )) || "inline") + "; #{filename.parameters}" + end end end |