Sha256: be6fb0f85e3c651bd74ae76858b6457a87319b258a68cf89ad6cd82e0ee70b11

Contents?: true

Size: 1.29 KB

Versions: 5

Compression:

Stored size: 1.29 KB

Contents

# direct method cannot be used inside engine routes
# see: https://github.com/rails/rails/issues/34872
Rails.application.routes.draw do
  direct :cdn_image do |model, options|
    options[:host] = Spree.cdn_host if Spree.cdn_host.present?
    options[:host] ||= Rails.application.routes.default_url_options[:host]

    options[:only_path] = true if options[:host].blank?

    if model.blob.service_name == 'cloudinary' && defined?(Cloudinary)
      if model.class.method_defined?(:has_mvariation)
        Cloudinary::Utils.cloudinary_url(model.blob.key,
          width: model.variation.transformations[:resize_to_limit].first,
          height: model.variation.transformations[:resize_to_limit].last,
          crop: :fill
        )
      else
        Cloudinary::Utils.cloudinary_url(model.blob.key)
      end
    elsif model.respond_to?(:signed_id)
      route_for(
        :rails_service_blob_proxy,
        model.signed_id,
        model.filename,
        options
      )
    else
      signed_blob_id = model.blob.signed_id
      variation_key  = model.variation.key
      filename       = model.blob.filename

      route_for(
        :rails_blob_representation_proxy,
        signed_blob_id,
        variation_key,
        filename,
        options
      )
    end
  end
end

Spree::Core::Engine.draw_routes

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
spree_core-4.10.1 config/routes.rb
spree_core-4.10.0 config/routes.rb
spree_core-4.9.0 config/routes.rb
spree_core-4.8.3 config/routes.rb
spree_core-4.8.2 config/routes.rb