2015-04-26 12:48:37 +05:30
|
|
|
module Projects
|
|
|
|
class UploadService < BaseService
|
|
|
|
def initialize(project, file)
|
|
|
|
@project, @file = project, file
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
|
|
|
return nil unless @file and @file.size <= max_attachment_size
|
|
|
|
|
|
|
|
uploader = FileUploader.new(@project)
|
|
|
|
uploader.store!(@file)
|
|
|
|
|
|
|
|
filename = uploader.image? ? uploader.file.basename : uploader.file.filename
|
|
|
|
|
|
|
|
{
|
2015-09-25 12:07:36 +05:30
|
|
|
alt: filename,
|
|
|
|
url: uploader.secure_url,
|
|
|
|
is_image: uploader.image?
|
2015-04-26 12:48:37 +05:30
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def max_attachment_size
|
|
|
|
current_application_settings.max_attachment_size.megabytes.to_i
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|