2017-07-03 14:14:28 -04:00
|
|
|
class ActiveFile::DiskController < ActionController::Base
|
|
|
|
def show
|
2017-07-03 15:06:09 -04:00
|
|
|
if key = decode_verified_key
|
|
|
|
blob = ActiveFile::Blob.find_by!(key: key)
|
2017-07-03 14:14:28 -04:00
|
|
|
send_data blob.download, filename: blob.filename, type: blob.content_type, disposition: disposition_param
|
2017-07-03 15:06:09 -04:00
|
|
|
else
|
|
|
|
head :not_found
|
2017-07-03 14:14:28 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2017-07-03 15:06:09 -04:00
|
|
|
def decode_verified_key
|
2017-07-04 11:36:29 -04:00
|
|
|
ActiveFile::Site::DiskSite::VerifiedKeyWithExpiration.decode(params[:encoded_key])
|
2017-07-03 14:14:28 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def disposition_param
|
|
|
|
params[:disposition].presence_in(%w( inline attachment )) || 'inline'
|
|
|
|
end
|
|
|
|
end
|