diff options
-rw-r--r-- | app/controllers/projects/uploads_controller.rb | 2 | ||||
-rw-r--r-- | app/services/projects/upload_service.rb | 3 | ||||
-rw-r--r-- | app/uploaders/file_uploader.rb | 4 | ||||
-rw-r--r-- | config/routes.rb | 6 |
4 files changed, 9 insertions, 6 deletions
diff --git a/app/controllers/projects/uploads_controller.rb b/app/controllers/projects/uploads_controller.rb index 53b92d8643d..9020e86c44e 100644 --- a/app/controllers/projects/uploads_controller.rb +++ b/app/controllers/projects/uploads_controller.rb @@ -4,7 +4,7 @@ class Projects::UploadsController < Projects::ApplicationController before_filter :project def create - link_to_file = ::Projects::UploadService.new(repository, params[:file]). + link_to_file = ::Projects::UploadService.new(project, params[:file]). execute respond_to do |format| diff --git a/app/services/projects/upload_service.rb b/app/services/projects/upload_service.rb index b2466b52ad9..a186c97628f 100644 --- a/app/services/projects/upload_service.rb +++ b/app/services/projects/upload_service.rb @@ -1,6 +1,5 @@ module Projects class UploadService < BaseService - include Rails.application.routes.url_helpers def initialize(project, file) @project, @file = project, file end @@ -15,7 +14,7 @@ module Projects { 'alt' => filename, - 'url' => project_upload_url(@project, secret: uploader.secret, filename: uploader.file.filename), + 'url' => uploader.secure_url, 'is_image' => uploader.image? } end diff --git a/app/uploaders/file_uploader.rb b/app/uploaders/file_uploader.rb index 36a28f93c49..f9673abbfe8 100644 --- a/app/uploaders/file_uploader.rb +++ b/app/uploaders/file_uploader.rb @@ -25,6 +25,10 @@ class FileUploader < CarrierWave::Uploader::Base SecureRandom.hex end + def secure_url + File.join(Gitlab.config.gitlab.url, @project.path_with_namespace, "uploads", @secret, file.filename) + end + def file_storage? self.class.storage == CarrierWave::Storage::File end diff --git a/config/routes.rb b/config/routes.rb index 498716b12e0..b6f58acf1a6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -79,8 +79,8 @@ Gitlab::Application.routes.draw do constraints: { model: /note|user|group|project/, mounted_as: /avatar|attachment/, filename: /.+/ } # Project markdown uploads - get ":id/:secret/:filename", to: "projects/uploads#show", - constraints: { id: /[a-zA-Z.0-9_\-]+\/[a-zA-Z.0-9_\-]+/, filename: /.+/ } + get ":project_id/:secret/:filename", to: "projects/uploads#show", + constraints: { project_id: /[a-zA-Z.0-9_\-]+\/[a-zA-Z.0-9_\-]+/, filename: /.+/ } end # @@ -264,7 +264,7 @@ Gitlab::Application.routes.draw do resources :uploads, only: [:create] do collection do - get ":secret/:filename", action: :show, constraints: { filename: /.+/ } + get ":secret/:filename", action: :show, as: :show, constraints: { filename: /.+/ } end end |