Sha256: f3cc9bddc75dc15918145a16937fad9e10cfd93238d11823368d8fe31a39b955

Contents?: true

Size: 773 Bytes

Versions: 1

Compression:

Stored size: 773 Bytes

Contents

require "action_controller"
require "active_storage/blob"
require "active_storage/verified_key_with_expiration"

require "active_support/core_ext/object/inclusion"

class ActiveStorage::DiskController < ActionController::Base
  def show
    if key = decode_verified_key
      blob = ActiveStorage::Blob.find_by!(key: key)
      
      if stale?(etag: blob.checksum)
        send_data blob.download, filename: blob.filename, type: blob.content_type, disposition: disposition_param
      end
    else
      head :not_found
    end
  end

  private
    def decode_verified_key
      ActiveStorage::VerifiedKeyWithExpiration.decode(params[:encoded_key])
    end

    def disposition_param
      params[:disposition].presence_in(%w( inline attachment )) || 'inline'
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activestorage-0.1 lib/active_storage/disk_controller.rb