Class: Spree::Api::V2::Storefront::DigitalsController
- Inherits:
-
ResourceController
- Object
- ActionController::API
- BaseController
- ResourceController
- Spree::Api::V2::Storefront::DigitalsController
- Defined in:
- app/controllers/spree/api/v2/storefront/digitals_controller.rb
Instance Method Summary collapse
Methods inherited from ResourceController
Methods included from Caching
#collection_cache_key, #collection_cache_opts
Methods included from CollectionOptionsHelpers
#collection_links, #collection_meta, #collection_permitted_params
Methods inherited from BaseController
Instance Method Details
#download ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/controllers/spree/api/v2/storefront/digitals_controller.rb', line 6 def download if .present? if digital_link. if defined?(ActiveStorage::Service::DiskService) && ActiveStorage::Blob.service.instance_of?(ActiveStorage::Service::DiskService) # The asset is hosted on disk, use send_file. send_file( ActiveStorage::Blob.service.path_for(.key), filename: .filename.to_s, type: .content_type.to_s, status: :ok ) and return else # The asset is hosted on a 3rd party service, use an expiring url with disposition: 'attachment'. redirect_to .url( expires_in: current_store.digital_asset_link_expire_time.seconds, disposition: 'attachment', host: ) and return end end else Rails.logger.error I18n.t('spree.api.v2.digitals.missing_file') end render json: { error: I18n.t('spree.api.v2.digitals.unauthorized') }, status: 403 end |