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

uploads_controller.rb 840 Bytes
Newer Older
1
class Projects::UploadsController < Projects::ApplicationController
2 3
  include UploadsActions

4 5
  skip_before_action :project, :repository,
    if: -> { action_name == 'show' && image_or_video? }
6

Douwe Maan's avatar
Douwe Maan committed
7
  before_action :authorize_upload_file!, only: [:create]
Douwe Maan's avatar
Douwe Maan committed
8 9 10

  private

Douwe Maan's avatar
Douwe Maan committed
11 12 13
  def uploader
    return @uploader if defined?(@uploader)

14 15
    namespace = params[:namespace_id]
    id = params[:project_id]
Douwe Maan's avatar
Douwe Maan committed
16

17
    file_project = Project.find_by_full_path("#{namespace}/#{id}")
18

Douwe Maan's avatar
Douwe Maan committed
19
    if file_project.nil?
20
      @uploader = nil
Douwe Maan's avatar
Douwe Maan committed
21 22
      return
    end
23

Douwe Maan's avatar
Douwe Maan committed
24 25
    @uploader = FileUploader.new(file_project, params[:secret])
    @uploader.retrieve_from_store!(params[:filename])
26

Douwe Maan's avatar
Douwe Maan committed
27
    @uploader
28
  end
29

30
  def image_or_video?
31
    uploader && uploader.exists? && uploader.image_or_video?
32
  end
33 34 35 36 37 38

  def uploader_class
    FileUploader
  end

  alias_method :model, :project
Douwe Maan's avatar
Douwe Maan committed
39
end