diff options
author | Douwe Maan <douwe@gitlab.com> | 2016-01-08 17:38:53 +0100 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2016-01-08 17:38:53 +0100 |
commit | 0614793b38db4711053cbcb4fa80d9c8cc492eec (patch) | |
tree | 528e7b413ea84dd45bc2c02e9820c6d18e3f2d38 /app | |
parent | 1e927d39b4bf6d1177dee0dd4a6c60bf270db3f2 (diff) | |
download | gitlab-ce-0614793b38db4711053cbcb4fa80d9c8cc492eec.tar.gz |
DRY up upload and download servicesapi-project-upload
Diffstat (limited to 'app')
-rw-r--r-- | app/services/projects/download_service.rb | 13 | ||||
-rw-r--r-- | app/services/projects/upload_service.rb | 13 | ||||
-rw-r--r-- | app/uploaders/file_uploader.rb | 15 |
3 files changed, 17 insertions, 24 deletions
diff --git a/app/services/projects/download_service.rb b/app/services/projects/download_service.rb index b846a59ed94..6386f57fb0d 100644 --- a/app/services/projects/download_service.rb +++ b/app/services/projects/download_service.rb @@ -16,18 +16,7 @@ module Projects uploader.download!(@url) uploader.store! - filename = uploader.image? ? uploader.file.basename : uploader.file.filename - - escaped_filename = filename.gsub("]", "\\]") - markdown = "[#{escaped_filename}](#{uploader.secure_url})" - markdown.prepend("!") if uploader.image? - - { - 'alt' => filename, - 'url' => uploader.secure_url, - 'is_image' => uploader.image?, - 'markdown' => markdown - } + uploader.to_h end private diff --git a/app/services/projects/upload_service.rb b/app/services/projects/upload_service.rb index 36ccf1cda12..012e82a7704 100644 --- a/app/services/projects/upload_service.rb +++ b/app/services/projects/upload_service.rb @@ -10,18 +10,7 @@ module Projects uploader = FileUploader.new(@project) uploader.store!(@file) - filename = uploader.image? ? uploader.file.basename : uploader.file.filename - - escaped_filename = filename.gsub("]", "\\]") - markdown = "[#{escaped_filename}](#{uploader.secure_url})" - markdown.prepend("!") if uploader.image? - - { - alt: filename, - url: uploader.secure_url, - is_image: uploader.image?, - markdown: markdown - } + uploader.to_h end private diff --git a/app/uploaders/file_uploader.rb b/app/uploaders/file_uploader.rb index ac920119a85..86d24469e05 100644 --- a/app/uploaders/file_uploader.rb +++ b/app/uploaders/file_uploader.rb @@ -30,4 +30,19 @@ class FileUploader < CarrierWave::Uploader::Base def secure_url File.join("/uploads", @secret, file.filename) end + + def to_h + filename = image? ? self.file.basename : self.file.filename + escaped_filename = filename.gsub("]", "\\]") + + markdown = "[#{escaped_filename}](#{self.secure_url})" + markdown.prepend("!") if image? + + { + alt: filename, + url: self.secure_url, + is_image: image?, + markdown: markdown + } + end end |