BigW Consortium Gitlab

artifacts_controller.rb 1.18 KB
Newer Older
1
class Projects::ArtifactsController < Projects::ApplicationController
2
  layout 'project'
3
  before_action :authorize_read_build!
4
  before_action :authorize_update_build!, only: [:keep]
5
  before_action :validate_artifacts!
6 7 8 9 10 11 12 13 14

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

    send_file artifacts_file.path, disposition: 'attachment'
  end

15
  def browse
16
    directory = params[:path] ? "#{params[:path]}/" : ''
17
    @entry = build.artifacts_metadata_entry(directory)
18

19
    return render_404 unless @entry.exists?
20 21
  end

22
  def file
23
    entry = build.artifacts_metadata_entry(params[:path])
24

25
    if entry.exists?
26
      render json: { archive: build.artifacts_file.path,
27
                     entry: Base64.encode64(entry.path) }
28 29 30
    else
      render json: {}, status: 404
    end
31 32
  end

33 34 35 36 37
  def keep
    build.keep_artifacts!
    redirect_to namespace_project_build_path(project.namespace, project, build)
  end

38 39
  private

40 41 42 43
  def validate_artifacts!
    render_404 unless build.artifacts?
  end

44
  def build
45
    @build ||= project.builds.find_by!(id: params[:build_id])
46 47 48 49 50 51
  end

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