2015-02-16 18:58:40 +00:00
|
|
|
module Projects
|
|
|
|
class UploadService < BaseService
|
|
|
|
def initialize(project, file)
|
|
|
|
@project, @file = project, file
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2017-02-21 22:31:14 +00:00
|
|
|
return nil unless @file && @file.size <= max_attachment_size
|
2015-02-16 18:58:40 +00:00
|
|
|
|
|
|
|
uploader = FileUploader.new(@project)
|
|
|
|
uploader.store!(@file)
|
|
|
|
|
2016-01-08 16:38:53 +00:00
|
|
|
uploader.to_h
|
2015-02-16 18:58:40 +00:00
|
|
|
end
|
2015-03-20 12:11:12 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def max_attachment_size
|
|
|
|
current_application_settings.max_attachment_size.megabytes.to_i
|
|
|
|
end
|
2015-02-16 18:58:40 +00:00
|
|
|
end
|
|
|
|
end
|