2015-12-18 07:41:16 +00:00
|
|
|
class Projects::ArtifactsController < Projects::ApplicationController
|
2015-12-17 13:24:43 +00:00
|
|
|
layout 'project'
|
2016-01-12 10:02:15 +00:00
|
|
|
before_action :authorize_read_build_artifacts!
|
2015-12-17 13:24:43 +00:00
|
|
|
|
|
|
|
def download
|
|
|
|
unless artifacts_file.file_storage?
|
|
|
|
return redirect_to artifacts_file.url
|
|
|
|
end
|
|
|
|
|
|
|
|
unless artifacts_file.exists?
|
|
|
|
return not_found!
|
|
|
|
end
|
|
|
|
|
|
|
|
send_file artifacts_file.path, disposition: 'attachment'
|
|
|
|
end
|
|
|
|
|
2015-12-18 07:41:16 +00:00
|
|
|
def browse
|
2015-12-28 10:43:15 +00:00
|
|
|
return render_404 unless build.artifacts?
|
2016-01-11 08:57:03 +00:00
|
|
|
|
|
|
|
directory = params[:path] ? "#{params[:path]}/" : ''
|
|
|
|
@path = build.artifacts_metadata_path(directory)
|
|
|
|
|
2016-01-04 13:18:06 +00:00
|
|
|
return render_404 unless @path.exists?
|
2015-12-17 14:17:00 +00:00
|
|
|
end
|
|
|
|
|
2016-01-09 13:41:43 +00:00
|
|
|
def file
|
2016-01-12 10:02:15 +00:00
|
|
|
file_path = build.artifacts_metadata_path(params[:path])
|
2016-01-11 09:01:18 +00:00
|
|
|
|
2016-01-12 10:02:15 +00:00
|
|
|
if file_path.exists?
|
|
|
|
render json: { archive: build.artifacts_file.path,
|
|
|
|
path: Base64.encode64(file_path.path) }
|
2016-01-11 09:01:18 +00:00
|
|
|
else
|
|
|
|
render json: {}, status: 404
|
|
|
|
end
|
2016-01-09 13:41:43 +00:00
|
|
|
end
|
|
|
|
|
2015-12-17 13:24:43 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def build
|
|
|
|
@build ||= project.builds.unscoped.find_by!(id: params[:build_id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def artifacts_file
|
|
|
|
@artifacts_file ||= build.artifacts_file
|
|
|
|
end
|
|
|
|
|
2016-01-12 10:02:15 +00:00
|
|
|
def authorize_read_build_artifacts!
|
|
|
|
unless can?(current_user, :read_build_artifacts, @project)
|
2015-12-17 13:24:43 +00:00
|
|
|
if current_user.nil?
|
|
|
|
return authenticate_user!
|
|
|
|
else
|
|
|
|
return render_404
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|