aboutsummaryrefslogtreecommitdiffstats
path: root/lib/active_file/disk_controller.rb
blob: f016c90fc5d5f3d2d64b58d022e27c9f62ec9362 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
class ActiveFile::DiskController < ActionController::Base
  def show
    if key = decode_verified_key
      blob = ActiveFile::Blob.find_by!(key: key)
      send_data blob.download, filename: blob.filename, type: blob.content_type, disposition: disposition_param
    else
      head :not_found
    end
  end

  private
    def decode_verified_key
      ActiveFile::Site::DiskSite::VerifiedKeyWithExpiration.decode(params[:id])
    end

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