Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
9729cc58
Commit
9729cc58
authored
Feb 14, 2015
by
Hannes Rosenögger
Committed by
Douwe Maan
Feb 17, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement Project::UploadsController
parent
ca504a77
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
28 additions
and
34 deletions
+28
-34
app/controllers/files_controller.rb
app/controllers/files_controller.rb
+2
-27
app/controllers/projects/uploads_controller.rb
app/controllers/projects/uploads_controller.rb
+16
-0
app/uploaders/file_uploader.rb
app/uploaders/file_uploader.rb
+3
-1
config/routes.rb
config/routes.rb
+3
-2
spec/services/projects/file_service_spec.rb
spec/services/projects/file_service_spec.rb
+4
-4
No files found.
app/controllers/files_controller.rb
View file @
9729cc58
class
FilesController
<
ApplicationController
class
FilesController
<
ApplicationController
def
download
_notes
def
download
note
=
Note
.
find
(
params
[
:id
])
note
=
Note
.
find
(
params
[
:id
])
uploader
=
note
.
attachment
uploader
=
note
.
attachment
...
@@ -14,32 +14,7 @@ class FilesController < ApplicationController
...
@@ -14,32 +14,7 @@ class FilesController < ApplicationController
not_found!
not_found!
end
end
else
else
not_found!
redirect_to
uploader
.
url
end
end
end
end
def
download_files
namespace_id
=
params
[
:namespace
]
project_id
=
params
[
:project
]
folder_id
=
params
[
:folder_id
]
filename
=
params
[
:filename
]
project_with_namespace
=
"
#{
namespace_id
}
/
#{
project_id
}
"
filename_with_id
=
"
#{
folder_id
}
/
#{
filename
}
"
project
=
Project
.
find_with_namespace
(
project_with_namespace
)
uploader
=
FileUploader
.
new
(
"
#{
Rails
.
root
}
/uploads"
,
"
#{
project_with_namespace
}
/
#{
folder_id
}
"
)
uploader
.
retrieve_from_store!
(
filename
)
if
can?
(
current_user
,
:read_project
,
project
)
download
(
uploader
)
else
not_found!
end
end
def
download
(
uploader
)
disposition
=
uploader
.
image?
?
'inline'
:
'attachment'
send_file
uploader
.
file
.
path
,
disposition:
disposition
end
end
end
app/controllers/projects/uploads_controller.rb
0 → 100644
View file @
9729cc58
class
Projects::UploadsController
<
Projects
::
ApplicationController
layout
'project'
before_filter
:project
def
show
folder_id
=
params
[
:folder_id
]
filename
=
params
[
:filename
]
uploader
=
FileUploader
.
new
(
"
#{
Rails
.
root
}
/uploads"
,
"
#{
@project
.
path_with_namespace
}
/
#{
folder_id
}
"
)
uploader
.
retrieve_from_store!
(
filename
)
disposition
=
uploader
.
image?
?
'inline'
:
'attachment'
send_file
uploader
.
file
.
path
,
disposition:
disposition
end
end
app/uploaders/file_uploader.rb
View file @
9729cc58
...
@@ -40,7 +40,9 @@ class FileUploader < CarrierWave::Uploader::Base
...
@@ -40,7 +40,9 @@ class FileUploader < CarrierWave::Uploader::Base
end
end
def
secure_url
def
secure_url
Gitlab
.
config
.
gitlab
.
relative_url_root
+
"/files/
#{
@path
}
/
#{
@filename
}
"
path_array
=
@path
.
split
(
'/'
)
path
=
File
.
join
(
path_array
[
0
],
path_array
[
1
],
'uploads'
,
path_array
[
2
])
Gitlab
.
config
.
gitlab
.
relative_url_root
+
"/
#{
path
}
/
#{
@filename
}
"
end
end
def
image?
def
image?
...
...
config/routes.rb
View file @
9729cc58
...
@@ -93,8 +93,7 @@ Gitlab::Application.routes.draw do
...
@@ -93,8 +93,7 @@ Gitlab::Application.routes.draw do
#
#
# Attachments serving
# Attachments serving
#
#
get
'files/:type/:id/:filename'
=>
'files#download_notes'
,
constraints:
{
id:
/\d+/
,
type:
/[a-z]+/
,
filename:
/.+/
}
get
'files/:type/:id/:filename'
=>
'files#download'
,
constraints:
{
id:
/\d+/
,
type:
/[a-z]+/
,
filename:
/.+/
}
get
'files/:namespace/:project/:folder_id/:filename'
=>
'files#download_files'
,
constraints:
{
namespace:
/[^\/]+/
,
project:
/[a-zA-Z.\/0-9_\-]+/
,
filename:
/.+/
}
#
#
# Admin Area
# Admin Area
...
@@ -257,6 +256,8 @@ Gitlab::Application.routes.draw do
...
@@ -257,6 +256,8 @@ Gitlab::Application.routes.draw do
end
end
end
end
get
'/uploads/:folder_id/:filename'
=>
'uploads#show'
,
constraints:
{
filename:
/.+/
}
get
'/compare/:from...:to'
=>
'compare#show'
,
:as
=>
'compare'
,
get
'/compare/:from...:to'
=>
'compare#show'
,
:as
=>
'compare'
,
:constraints
=>
{
from:
/.+/
,
to:
/.+/
}
:constraints
=>
{
from:
/.+/
,
to:
/.+/
}
...
...
spec/services/projects/file_service_spec.rb
View file @
9729cc58
...
@@ -20,7 +20,7 @@ describe Projects::FileService do
...
@@ -20,7 +20,7 @@ describe Projects::FileService do
it
{
expect
(
@link_to_file
).
to
have_key
(
'is_image'
)
}
it
{
expect
(
@link_to_file
).
to
have_key
(
'is_image'
)
}
it
{
expect
(
@link_to_file
).
to
have_value
(
'banana_sample'
)
}
it
{
expect
(
@link_to_file
).
to
have_value
(
'banana_sample'
)
}
it
{
expect
(
@link_to_file
[
'is_image'
]).
to
equal
(
true
)
}
it
{
expect
(
@link_to_file
[
'is_image'
]).
to
equal
(
true
)
}
it
{
expect
(
@link_to_file
[
'url'
]).
to
match
(
"/
files/
#{
@project
.
path_with_namespace
}
"
)
}
it
{
expect
(
@link_to_file
[
'url'
]).
to
match
(
"/
#{
@project
.
path_with_namespace
}
"
)
}
it
{
expect
(
@link_to_file
[
'url'
]).
to
match
(
'banana_sample.gif'
)
}
it
{
expect
(
@link_to_file
[
'url'
]).
to
match
(
'banana_sample.gif'
)
}
end
end
...
@@ -38,7 +38,7 @@ describe Projects::FileService do
...
@@ -38,7 +38,7 @@ describe Projects::FileService do
it
{
expect
(
@link_to_file
).
to
have_value
(
'dk'
)
}
it
{
expect
(
@link_to_file
).
to
have_value
(
'dk'
)
}
it
{
expect
(
@link_to_file
).
to
have_key
(
'is_image'
)
}
it
{
expect
(
@link_to_file
).
to
have_key
(
'is_image'
)
}
it
{
expect
(
@link_to_file
[
'is_image'
]).
to
equal
(
true
)
}
it
{
expect
(
@link_to_file
[
'is_image'
]).
to
equal
(
true
)
}
it
{
expect
(
@link_to_file
[
'url'
]).
to
match
(
"/
files/
#{
@project
.
path_with_namespace
}
"
)
}
it
{
expect
(
@link_to_file
[
'url'
]).
to
match
(
"/
#{
@project
.
path_with_namespace
}
"
)
}
it
{
expect
(
@link_to_file
[
'url'
]).
to
match
(
'dk.png'
)
}
it
{
expect
(
@link_to_file
[
'url'
]).
to
match
(
'dk.png'
)
}
end
end
...
@@ -53,7 +53,7 @@ describe Projects::FileService do
...
@@ -53,7 +53,7 @@ describe Projects::FileService do
it
{
expect
(
@link_to_file
).
to
have_key
(
'is_image'
)
}
it
{
expect
(
@link_to_file
).
to
have_key
(
'is_image'
)
}
it
{
expect
(
@link_to_file
).
to
have_value
(
'rails_sample'
)
}
it
{
expect
(
@link_to_file
).
to
have_value
(
'rails_sample'
)
}
it
{
expect
(
@link_to_file
[
'is_image'
]).
to
equal
(
true
)
}
it
{
expect
(
@link_to_file
[
'is_image'
]).
to
equal
(
true
)
}
it
{
expect
(
@link_to_file
[
'url'
]).
to
match
(
"/
files/
#{
@project
.
path_with_namespace
}
"
)
}
it
{
expect
(
@link_to_file
[
'url'
]).
to
match
(
"/
#{
@project
.
path_with_namespace
}
"
)
}
it
{
expect
(
@link_to_file
[
'url'
]).
to
match
(
'rails_sample.jpg'
)
}
it
{
expect
(
@link_to_file
[
'url'
]).
to
match
(
'rails_sample.jpg'
)
}
end
end
...
@@ -70,7 +70,7 @@ describe Projects::FileService do
...
@@ -70,7 +70,7 @@ describe Projects::FileService do
it
{
expect
(
@link_to_file
).
to
have_key
(
'is_image'
)
}
it
{
expect
(
@link_to_file
).
to
have_key
(
'is_image'
)
}
it
{
expect
(
@link_to_file
).
to
have_value
(
'doc_sample.txt'
)
}
it
{
expect
(
@link_to_file
).
to
have_value
(
'doc_sample.txt'
)
}
it
{
expect
(
@link_to_file
[
'is_image'
]).
to
equal
(
false
)
}
it
{
expect
(
@link_to_file
[
'is_image'
]).
to
equal
(
false
)
}
it
{
expect
(
@link_to_file
[
'url'
]).
to
match
(
"/
files/
#{
@project
.
path_with_namespace
}
"
)
}
it
{
expect
(
@link_to_file
[
'url'
]).
to
match
(
"/
#{
@project
.
path_with_namespace
}
"
)
}
it
{
expect
(
@link_to_file
[
'url'
]).
to
match
(
'doc_sample.txt'
)
}
it
{
expect
(
@link_to_file
[
'url'
]).
to
match
(
'doc_sample.txt'
)
}
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment