debian-mirror-gitlab/app/controllers/projects/uploads_controller.rb

52 lines
1.2 KiB
Ruby
Raw Normal View History

2015-04-26 12:48:37 +05:30
class Projects::UploadsController < Projects::ApplicationController
2015-09-11 14:41:01 +05:30
skip_before_action :authenticate_user!, :reject_blocked!, :project,
:repository, if: -> { action_name == 'show' && image? }
2015-04-26 12:48:37 +05:30
def create
link_to_file = ::Projects::UploadService.new(project, params[:file]).
execute
respond_to do |format|
if link_to_file
format.json do
render json: { link: link_to_file }
end
else
format.json do
render json: 'Invalid file.', status: :unprocessable_entity
end
end
end
end
def show
2015-10-24 18:46:33 +05:30
return render_404 if uploader.nil? || !uploader.file.exists?
2015-04-26 12:48:37 +05:30
disposition = uploader.image? ? 'inline' : 'attachment'
send_file uploader.file.path, disposition: disposition
end
def uploader
return @uploader if defined?(@uploader)
namespace = params[:namespace_id]
id = params[:project_id]
file_project = Project.find_with_namespace("#{namespace}/#{id}")
if file_project.nil?
2015-09-11 14:41:01 +05:30
@uploader = nil
2015-04-26 12:48:37 +05:30
return
end
@uploader = FileUploader.new(file_project, params[:secret])
@uploader.retrieve_from_store!(params[:filename])
@uploader
end
def image?
uploader && uploader.file.exists? && uploader.image?
end
end