Fix URL to uploaded file.

This commit is contained in:
Douwe Maan 2015-02-20 15:56:12 +01:00
parent 218283b368
commit 7f1adc3d9c
4 changed files with 9 additions and 6 deletions

View file

@ -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|

View file

@ -1,6 +1,5 @@
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
{ {
'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

View file

@ -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

View file

@ -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
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