GitLab steht Mittwoch, den 23. September, zwischen 10:00 und 12:00 Uhr aufgrund von Wartungsarbeiten nicht zur Verfügung.

uploads_controller.rb 1.24 KB
Newer Older
1
class Projects::UploadsController < Projects::ApplicationController
2
  layout 'project'
3

4 5 6
  skip_before_filter :project, :repository, :authenticate_user!, only: [:show]

  before_filter :authorize_uploads, only: [:show]
7

Douwe Maan's avatar
Douwe Maan committed
8
  def create
Douwe Maan's avatar
Douwe Maan committed
9
    link_to_file = ::Projects::UploadService.new(project, params[:file]).
Douwe Maan's avatar
Douwe Maan committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
      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

25
  def show
26 27 28 29 30 31 32 33 34 35 36
    uploader = get_file
    
    return not_found! if uploader.nil? || !uploader.file.exists?

    disposition = uploader.image? ? 'inline' : 'attachment'
    send_file uploader.file.path, disposition: disposition
  end

  def get_file
    namespace = params[:namespace_id]
    id = params[:project_id]
Douwe Maan's avatar
Douwe Maan committed
37

38
    file_project = Project.find_with_namespace("#{namespace}/#{id}")
39

40 41 42
    return nil if file_project.nil?

    uploader = FileUploader.new(file_project, params[:secret])
43 44
    uploader.retrieve_from_store!(params[:filename])

45 46
    uploader
  end
47

48 49 50 51 52
  def authorize_uploads
    uploader = get_file
    unless uploader && uploader.image?
      project
    end
53
  end
Douwe Maan's avatar
Douwe Maan committed
54
end