Class: Spree::DigitalLinksController

Inherits:
StoreController show all
Defined in:
app/controllers/spree/digital_links_controller.rb

Instance Method Summary collapse

Methods inherited from StoreController

#current_taxon, #default_products_sort, #permitted_products_params, #products_filters_params, #render_404_if_store_not_exists, #store_filter_names, #store_filter_names_hash

Methods included from AnalyticsHelper

#analytics_event_handlers, #track_event, #unsupported_event?, #visitor_id

Methods included from WishlistHelper

#current_wishlist

Methods included from PasswordProtected

#redirect_to_password

Methods included from StorefrontHelper

#as_aspect_ratio, #page_description, #page_image, #paths_equal?, #render_storefront_partials, #show_account_pane?, #svg_country_icon, #tailwind_classes_for

Methods included from ThemeConcern

#default_url_options, #set_theme_view_paths

Instance Method Details

#showObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/spree/digital_links_controller.rb', line 3

def show
  if digital_link.authorize!
    mark_shipment_as_fullfiled if digital_link.access_counter == 1

    if defined?(ActiveStorage::Service::DiskService) && ActiveStorage::Blob.service.instance_of?(ActiveStorage::Service::DiskService)
      send_file(
        ActiveStorage::Blob.service.path_for(attachment.key),
        filename: digital_link.filename.to_s,
        type: digital_link.content_type.to_s,
        status: :ok
        ) and return
    else
      redirect_to attachment.url(
        expires_in: current_store.preferred_digital_asset_link_expire_time.seconds,
        disposition: 'attachment'
      ), allow_other_host: true and return
    end
  end

  flash[:error] = Spree.t(:digital_link_unauthorized)
  redirect_to spree.order_path(digital_link.order)
end