From d2ff19c39c097aa17d16e33c8de981f43cd1ffa0 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 3 Jul 2017 20:14:28 +0200 Subject: WIP: Disk URLs --- lib/active_file/disk_controller.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 lib/active_file/disk_controller.rb (limited to 'lib/active_file/disk_controller.rb') diff --git a/lib/active_file/disk_controller.rb b/lib/active_file/disk_controller.rb new file mode 100644 index 0000000000..7d94b02f5c --- /dev/null +++ b/lib/active_file/disk_controller.rb @@ -0,0 +1,20 @@ +# FIXME: To be used by DiskSite#url +class ActiveFile::DiskController < ActionController::Base + def show + if verified_key.expired? + head :gone + else + blob = ActiveFile::Blob.find_by!(key: verified_key.to_s) + send_data blob.download, filename: blob.filename, type: blob.content_type, disposition: disposition_param + end + end + + private + def verified_key + ActiveFile::Sites::DiskSite::VerifiedKeyWithExpiration.new(params[:id]) + end + + def disposition_param + params[:disposition].presence_in(%w( inline attachment )) || 'inline' + end +end -- cgit v1.2.3