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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
3b2b3cff
Commit
3b2b3cff
authored
May 26, 2014
by
Marin Jankovski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move logic to image_service.
parent
8bec6b0b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
12 deletions
+43
-12
app/controllers/projects_controller.rb
app/controllers/projects_controller.rb
+3
-11
app/services/projects/image_service.rb
app/services/projects/image_service.rb
+39
-0
spec/controllers/commits_controller_spec.rb
spec/controllers/commits_controller_spec.rb
+1
-1
No files found.
app/controllers/projects_controller.rb
View file @
3b2b3cff
...
@@ -163,19 +163,11 @@ class ProjectsController < ApplicationController
...
@@ -163,19 +163,11 @@ class ProjectsController < ApplicationController
end
end
def
upload_image
def
upload_image
uploader
=
FileUploader
.
new
(
'uploads'
,
upload_path
,
accepted_images
)
link_to_image
=
::
Projects
::
ImageService
.
new
(
repository
,
params
,
root_url
).
execute
image
=
params
[
'markdown_img'
]
if
image
&&
accepted_images
.
map
{
|
format
|
image
.
content_type
.
include?
format
}.
any?
alt
=
image
.
original_filename
uploader
.
store!
(
image
)
link
=
{
'alt'
=>
File
.
basename
(
alt
,
'.*'
),
'url'
=>
File
.
join
(
root_url
,
uploader
.
url
)
}
end
respond_to
do
|
format
|
respond_to
do
|
format
|
if
link
if
link
_to_image
format
.
json
{
render
json:
{
link:
link
}
}
format
.
json
{
render
json:
{
link:
link
_to_image
}
}
else
else
format
.
json
{
render
json:
"Invalid file."
,
status: :unprocessable_entity
}
format
.
json
{
render
json:
"Invalid file."
,
status: :unprocessable_entity
}
end
end
...
...
app/services/projects/image_service.rb
0 → 100644
View file @
3b2b3cff
module
Projects
class
ImageService
<
BaseService
include
Rails
.
application
.
routes
.
url_helpers
def
initialize
(
repository
,
params
,
root_url
)
@repository
,
@params
,
@root_url
=
repository
,
params
.
dup
,
root_url
end
def
execute
uploader
=
FileUploader
.
new
(
'uploads'
,
upload_path
,
accepted_images
)
image
=
@params
[
'markdown_img'
]
if
image
&&
correct_mime_type?
(
image
)
alt
=
image
.
original_filename
uploader
.
store!
(
image
)
link
=
{
'alt'
=>
File
.
basename
(
alt
,
'.*'
),
'url'
=>
File
.
join
(
@root_url
,
uploader
.
url
)
}
else
link
=
nil
end
end
protected
def
upload_path
base_dir
=
FileUploader
.
generate_dir
File
.
join
(
@repository
.
path_with_namespace
,
base_dir
)
end
def
accepted_images
%w(png jpg jpeg gif)
end
def
correct_mime_type?
(
image
)
accepted_images
.
map
{
|
format
|
image
.
content_type
.
include?
format
}.
any?
end
end
end
spec/controllers/commits_controller_spec.rb
View file @
3b2b3cff
...
@@ -6,7 +6,7 @@ describe Projects::CommitsController do
...
@@ -6,7 +6,7 @@ describe Projects::CommitsController do
before
do
before
do
sign_in
(
user
)
sign_in
(
user
)
project
.
creator
=
user
project
.
team
<<
[
user
,
:master
]
end
end
describe
"GET show"
do
describe
"GET show"
do
...
...
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