# frozen_string_literal: true

if [:local, :test].include? Rails.application.config.active_storage.service
  module ActiveStorage
    class RepresentationsController < BaseController
      include ActiveStorage::SetBlob

      def show
        expires_in 1.year, public: true

        type = @blob.content_type || DEFAULT_SEND_FILE_TYPE

        if webp?
          variant = @blob.variant({convert: 'web'}).processed
          type = 'image/webp'
        else
          variant = @blob.representation(params[:variation_key]).processed
        end

        send_data @blob.service.download(variant.key),
          type: type, disposition: 'inline'
      end

      private

      def webp?
        request.headers['Accept'] =~ /image\/webp/
      end
    end
  end
end

# frozen_string_literal: true

if [:local, :test].include? Rails.application.config.active_storage.service
  module ActiveStorage
    class RepresentationsController < BaseController
      include ActiveStorage::SetBlob

      def show
        expires_in 1.year, public: true

        variant = @blob.representation(params[:variation_key]).processed

        send_data @blob.service.download(variant.key),
          type: @blob.content_type || DEFAULT_SEND_FILE_TYPE,
          disposition: 'inline'
      end
    end
  end
end

Revert "Return webp if browser supports it"
Revert "Return webp if browser supports it"

This reverts commit 0db9ec7fadc8c51cd74fb3c0731c18f4a4abc27b.
