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