Commit 7f1adc3d authored by Douwe Maan's avatar Douwe Maan

Fix URL to uploaded file.

parent 218283b3
...@@ -4,7 +4,7 @@ class Projects::UploadsController < Projects::ApplicationController ...@@ -4,7 +4,7 @@ class Projects::UploadsController < Projects::ApplicationController
before_filter :project before_filter :project
def create def create
link_to_file = ::Projects::UploadService.new(repository, params[:file]). link_to_file = ::Projects::UploadService.new(project, params[:file]).
execute execute
respond_to do |format| respond_to do |format|
......
module Projects module Projects
class UploadService < BaseService class UploadService < BaseService
include Rails.application.routes.url_helpers
def initialize(project, file) def initialize(project, file)
@project, @file = project, file @project, @file = project, file
end end
...@@ -15,7 +14,7 @@ module Projects ...@@ -15,7 +14,7 @@ module Projects
{ {
'alt' => filename, 'alt' => filename,
'url' => project_upload_url(@project, secret: uploader.secret, filename: uploader.file.filename), 'url' => uploader.secure_url,
'is_image' => uploader.image? 'is_image' => uploader.image?
} }
end end
......
...@@ -25,6 +25,10 @@ class FileUploader < CarrierWave::Uploader::Base ...@@ -25,6 +25,10 @@ class FileUploader < CarrierWave::Uploader::Base
SecureRandom.hex SecureRandom.hex
end end
def secure_url
File.join(Gitlab.config.gitlab.url, @project.path_with_namespace, "uploads", @secret, file.filename)
end
def file_storage? def file_storage?
self.class.storage == CarrierWave::Storage::File self.class.storage == CarrierWave::Storage::File
end end
......
...@@ -79,8 +79,8 @@ Gitlab::Application.routes.draw do ...@@ -79,8 +79,8 @@ Gitlab::Application.routes.draw do
constraints: { model: /note|user|group|project/, mounted_as: /avatar|attachment/, filename: /.+/ } constraints: { model: /note|user|group|project/, mounted_as: /avatar|attachment/, filename: /.+/ }
# Project markdown uploads # Project markdown uploads
get ":id/:secret/:filename", to: "projects/uploads#show", get ":project_id/:secret/:filename", to: "projects/uploads#show",
constraints: { id: /[a-zA-Z.0-9_\-]+\/[a-zA-Z.0-9_\-]+/, filename: /.+/ } constraints: { project_id: /[a-zA-Z.0-9_\-]+\/[a-zA-Z.0-9_\-]+/, filename: /.+/ }
end end
# #
...@@ -264,7 +264,7 @@ Gitlab::Application.routes.draw do ...@@ -264,7 +264,7 @@ Gitlab::Application.routes.draw do
resources :uploads, only: [:create] do resources :uploads, only: [:create] do
collection do collection do
get ":secret/:filename", action: :show, constraints: { filename: /.+/ } get ":secret/:filename", action: :show, as: :show, constraints: { filename: /.+/ }
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment