debian-mirror-gitlab/app/services/upload_service.rb

23 lines
546 B
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
class UploadService
2018-11-08 19:23:39 +05:30
def initialize(model, file, uploader_class = FileUploader, **uploader_context)
@model, @file, @uploader_class, @uploader_context = model, file, uploader_class, uploader_context
2017-08-17 22:00:37 +05:30
end
def execute
return nil unless @file && @file.size <= max_attachment_size
2018-11-08 19:23:39 +05:30
uploader = @uploader_class.new(@model, nil, @uploader_context)
2017-08-17 22:00:37 +05:30
uploader.store!(@file)
2019-02-15 15:39:39 +05:30
uploader
2017-08-17 22:00:37 +05:30
end
private
def max_attachment_size
2018-03-17 18:26:18 +05:30
Gitlab::CurrentSettings.max_attachment_size.megabytes.to_i
2017-08-17 22:00:37 +05:30
end
end