BigW Consortium Gitlab

artifacts_controller.rb 1 KB
Newer Older
1
class Projects::ArtifactsController < Projects::ApplicationController
2
  layout 'project'
3
  before_action :authorize_read_build!
4 5 6 7 8 9 10

  def download
    unless artifacts_file.file_storage?
      return redirect_to artifacts_file.url
    end

    unless artifacts_file.exists?
11
      return render_404
12 13 14 15 16
    end

    send_file artifacts_file.path, disposition: 'attachment'
  end

17
  def browse
18
    return render_404 unless build.artifacts?
19 20

    directory = params[:path] ? "#{params[:path]}/" : ''
21
    @entry = build.artifacts_metadata_entry(directory)
22

23
    return render_404 unless @entry.exists?
24 25
  end

26
  def file
27
    entry = build.artifacts_metadata_entry(params[:path])
28

29
    if entry.exists?
30
      render json: { archive: build.artifacts_file.path,
31
                     entry: Base64.encode64(entry.path) }
32 33 34
    else
      render json: {}, status: 404
    end
35 36
  end

37 38 39
  private

  def build
40
    @build ||= project.builds.find_by!(id: params[:build_id])
41 42 43 44 45 46
  end

  def artifacts_file
    @artifacts_file ||= build.artifacts_file
  end
end