Welcome to mirror list, hosted at ThFree Co, Russian Federation.

upload_service.rb « services « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 39909ee4f82ba0809f1fc2c49dd56b23a5de6913 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# frozen_string_literal: true

class UploadService
  def initialize(model, file, uploader_class = FileUploader, **uploader_context)
    @model, @file, @uploader_class, @uploader_context = model, file, uploader_class, uploader_context
  end

  def execute
    return nil unless @file && @file.size <= max_attachment_size

    uploader = @uploader_class.new(@model, nil, @uploader_context)
    uploader.store!(@file)

    uploader.to_h
  end

  private

  def max_attachment_size
    Gitlab::CurrentSettings.max_attachment_size.megabytes.to_i
  end
end