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
Léo-Paul Géneau
gitlab-ce
Commits
0614793b
Commit
0614793b
authored
Jan 08, 2016
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DRY up upload and download services
parent
1e927d39
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
37 deletions
+30
-37
app/services/projects/download_service.rb
app/services/projects/download_service.rb
+1
-12
app/services/projects/upload_service.rb
app/services/projects/upload_service.rb
+1
-12
app/uploaders/file_uploader.rb
app/uploaders/file_uploader.rb
+15
-0
lib/gitlab/fogbugz_import/importer.rb
lib/gitlab/fogbugz_import/importer.rb
+1
-1
spec/services/projects/download_service_spec.rb
spec/services/projects/download_service_spec.rb
+12
-12
No files found.
app/services/projects/download_service.rb
View file @
0614793b
...
...
@@ -16,18 +16,7 @@ module Projects
uploader
.
download!
(
@url
)
uploader
.
store!
filename
=
uploader
.
image?
?
uploader
.
file
.
basename
:
uploader
.
file
.
filename
escaped_filename
=
filename
.
gsub
(
"]"
,
"
\\
]"
)
markdown
=
"[
#{
escaped_filename
}
](
#{
uploader
.
secure_url
}
)"
markdown
.
prepend
(
"!"
)
if
uploader
.
image?
{
'alt'
=>
filename
,
'url'
=>
uploader
.
secure_url
,
'is_image'
=>
uploader
.
image?
,
'markdown'
=>
markdown
}
uploader
.
to_h
end
private
...
...
app/services/projects/upload_service.rb
View file @
0614793b
...
...
@@ -10,18 +10,7 @@ module Projects
uploader
=
FileUploader
.
new
(
@project
)
uploader
.
store!
(
@file
)
filename
=
uploader
.
image?
?
uploader
.
file
.
basename
:
uploader
.
file
.
filename
escaped_filename
=
filename
.
gsub
(
"]"
,
"
\\
]"
)
markdown
=
"[
#{
escaped_filename
}
](
#{
uploader
.
secure_url
}
)"
markdown
.
prepend
(
"!"
)
if
uploader
.
image?
{
alt:
filename
,
url:
uploader
.
secure_url
,
is_image:
uploader
.
image?
,
markdown:
markdown
}
uploader
.
to_h
end
private
...
...
app/uploaders/file_uploader.rb
View file @
0614793b
...
...
@@ -30,4 +30,19 @@ class FileUploader < CarrierWave::Uploader::Base
def
secure_url
File
.
join
(
"/uploads"
,
@secret
,
file
.
filename
)
end
def
to_h
filename
=
image?
?
self
.
file
.
basename
:
self
.
file
.
filename
escaped_filename
=
filename
.
gsub
(
"]"
,
"
\\
]"
)
markdown
=
"[
#{
escaped_filename
}
](
#{
self
.
secure_url
}
)"
markdown
.
prepend
(
"!"
)
if
image?
{
alt:
filename
,
url:
self
.
secure_url
,
is_image:
image?
,
markdown:
markdown
}
end
end
lib/gitlab/fogbugz_import/importer.rb
View file @
0614793b
...
...
@@ -232,7 +232,7 @@ module Gitlab
return
nil
if
res
.
nil?
res
[
'markdown'
]
res
[
:markdown
]
end
def
build_attachment_url
(
rel_url
)
...
...
spec/services/projects/download_service_spec.rb
View file @
0614793b
...
...
@@ -33,12 +33,12 @@ describe Projects::DownloadService, services: true do
@link_to_file
=
download_file
(
@project
,
url
)
end
it
{
expect
(
@link_to_file
).
to
have_key
(
'alt'
)
}
it
{
expect
(
@link_to_file
).
to
have_key
(
'url'
)
}
it
{
expect
(
@link_to_file
).
to
have_key
(
'is_image'
)
}
it
{
expect
(
@link_to_file
[
'is_image'
]).
to
be
true
}
it
{
expect
(
@link_to_file
[
'url'
]).
to
match
(
'rails_sample.jpg'
)
}
it
{
expect
(
@link_to_file
[
'alt'
]).
to
eq
(
'rails_sample'
)
}
it
{
expect
(
@link_to_file
).
to
have_key
(
:alt
)
}
it
{
expect
(
@link_to_file
).
to
have_key
(
:url
)
}
it
{
expect
(
@link_to_file
).
to
have_key
(
:is_image
)
}
it
{
expect
(
@link_to_file
[
:is_image
]).
to
be
true
}
it
{
expect
(
@link_to_file
[
:url
]).
to
match
(
'rails_sample.jpg'
)
}
it
{
expect
(
@link_to_file
[
:alt
]).
to
eq
(
'rails_sample'
)
}
end
context
'a txt file'
do
...
...
@@ -47,12 +47,12 @@ describe Projects::DownloadService, services: true do
@link_to_file
=
download_file
(
@project
,
url
)
end
it
{
expect
(
@link_to_file
).
to
have_key
(
'alt'
)
}
it
{
expect
(
@link_to_file
).
to
have_key
(
'url'
)
}
it
{
expect
(
@link_to_file
).
to
have_key
(
'is_image'
)
}
it
{
expect
(
@link_to_file
[
'is_image'
]).
to
be
false
}
it
{
expect
(
@link_to_file
[
'url'
]).
to
match
(
'doc_sample.txt'
)
}
it
{
expect
(
@link_to_file
[
'alt'
]).
to
eq
(
'doc_sample.txt'
)
}
it
{
expect
(
@link_to_file
).
to
have_key
(
:alt
)
}
it
{
expect
(
@link_to_file
).
to
have_key
(
:url
)
}
it
{
expect
(
@link_to_file
).
to
have_key
(
:is_image
)
}
it
{
expect
(
@link_to_file
[
:is_image
]).
to
be
false
}
it
{
expect
(
@link_to_file
[
:url
]).
to
match
(
'doc_sample.txt'
)
}
it
{
expect
(
@link_to_file
[
:alt
]).
to
eq
(
'doc_sample.txt'
)
}
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