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