Fix URL to uploaded file.
This commit is contained in:
parent
218283b368
commit
7f1adc3d9c
4 changed files with 9 additions and 6 deletions
|
@ -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|
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue