2015-02-20 07:13:48 -05:00
|
|
|
class Projects::UploadsController < Projects::ApplicationController
|
2015-04-20 13:40:17 -04:00
|
|
|
skip_before_action :authenticate_user!, :reject_blocked!, :project,
|
|
|
|
:repository, if: -> { action_name == 'show' && image? }
|
2015-02-20 07:13:48 -05:00
|
|
|
|
2015-02-16 13:58:40 -05:00
|
|
|
def create
|
2015-02-20 09:56:12 -05:00
|
|
|
link_to_file = ::Projects::UploadService.new(project, params[:file]).
|
2015-02-16 13:58:40 -05:00
|
|
|
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
|
|
|
|
|
2015-02-20 07:13:48 -05:00
|
|
|
def show
|
2015-10-09 13:07:29 -04:00
|
|
|
return render_404 if uploader.nil? || !uploader.file.exists?
|
2015-04-14 11:02:17 -04:00
|
|
|
|
|
|
|
disposition = uploader.image? ? 'inline' : 'attachment'
|
|
|
|
send_file uploader.file.path, disposition: disposition
|
|
|
|
end
|
|
|
|
|
2015-04-17 05:33:53 -04:00
|
|
|
def uploader
|
|
|
|
return @uploader if defined?(@uploader)
|
|
|
|
|
2015-04-14 11:02:17 -04:00
|
|
|
namespace = params[:namespace_id]
|
|
|
|
id = params[:project_id]
|
2015-02-16 13:58:40 -05:00
|
|
|
|
2015-04-14 11:02:17 -04:00
|
|
|
file_project = Project.find_with_namespace("#{namespace}/#{id}")
|
2015-02-20 07:13:48 -05:00
|
|
|
|
2015-04-17 05:33:53 -04:00
|
|
|
if file_project.nil?
|
2015-04-16 08:03:37 -04:00
|
|
|
@uploader = nil
|
2015-04-17 05:33:53 -04:00
|
|
|
return
|
|
|
|
end
|
2015-04-14 11:02:17 -04:00
|
|
|
|
2015-04-17 05:33:53 -04:00
|
|
|
@uploader = FileUploader.new(file_project, params[:secret])
|
|
|
|
@uploader.retrieve_from_store!(params[:filename])
|
2015-02-20 07:13:48 -05:00
|
|
|
|
2015-04-17 05:33:53 -04:00
|
|
|
@uploader
|
2015-04-14 11:02:17 -04:00
|
|
|
end
|
2015-02-20 09:37:37 -05:00
|
|
|
|
2015-04-17 05:33:53 -04:00
|
|
|
def image?
|
|
|
|
uploader && uploader.file.exists? && uploader.image?
|
2015-02-20 07:13:48 -05:00
|
|
|
end
|
2015-02-20 08:39:35 -05:00
|
|
|
end
|