Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cleaning-portalmec
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Richard Fernando Heise Ferreira
cleaning-portalmec
Commits
646841be
Commit
646841be
authored
9 years ago
by
Mauricio Giacomini Girardello
Browse files
Options
Downloads
Patches
Plain Diff
refactoring chunks controller
parent
d8a94e8b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/controllers/chunks_controller.rb
+18
-9
18 additions, 9 deletions
app/controllers/chunks_controller.rb
with
18 additions
and
9 deletions
app/controllers/chunks_controller.rb
+
18
−
9
View file @
646841be
...
...
@@ -22,10 +22,8 @@ class ChunksController < ApplicationController
#POST /chunk
def
create
#chunk folder path based on the parameters
dir
=
"/tmp/
#{
params
[
:resumableIdentifier
]
}
"
#chunk path based on the parameters
chunk
=
"
#{
dir
}
/
#{
params
[
:resumableFilename
]
}
.part
#{
params
[
:resumableChunkNumber
]
}
"
chunk
=
resumable_chunk
params
[
:resumableChunkNumber
]
#Create chunks directory when not present on system
if
!
File
.
directory?
(
dir
)
...
...
@@ -44,11 +42,11 @@ class ChunksController < ApplicationController
if
(
currentSize
+
params
[
:resumableCurrentChunkSize
].
to_i
)
>=
filesize
#Create a target file
File
.
open
(
"
#{
dir
}
/
#{
params
[
:
resumable
F
ilename
]
}
"
,
"a"
)
do
|
target
|
File
.
open
(
resumable
_f
ilename
,
"a"
)
do
|
target
|
#Loop trough the chunks
for
i
in
1
..
params
[
:resumableChunkNumber
].
to_i
#Select the chunk
chunk
=
File
.
open
(
"
#{
dir
}
/
#{
params
[
:resumableFilename
]
}
.part
#{
i
}
"
,
'r'
).
read
chunk
=
File
.
open
(
resumable_chunk
(
i
)
,
'r'
).
read
#Write chunk into target file
chunk
.
each_line
do
|
line
|
...
...
@@ -56,14 +54,13 @@ class ChunksController < ApplicationController
end
#Deleting chunk
FileUtils
.
rm
"
#{
dir
}
/
#{
params
[
:resumableFilename
]
}
.part
#{
i
}
"
,
:force
=>
true
FileUtils
.
rm
resumable_chunk
(
i
)
,
:force
=>
true
end
puts
"File saved to
#{
dir
}
/
#{
params
[
:resumableFilename
]
}
"
puts
"File saved to
#{
resumable_filename
}
"
end
publisher
=
LearningObjectPublisher
.
new
(
DspaceService
.
create_client
)
publisher
.
publish
publisher
.
publish
@learning_object
,
resumable_filename
end
render
:nothing
=>
true
,
:status
=>
200
...
...
@@ -71,6 +68,18 @@ class ChunksController < ApplicationController
private
def
resumable_chunk
(
part
)
"
#{
resumable_filename
}
.part
#{
part
}
"
end
def
resumable_filename
"
#{
dir
}
/
#{
params
[
:resumableFilename
]
}
"
end
def
dir
"/tmp/
#{
params
[
:resumableIdentifier
]
}
"
end
def
set_learning_object
@learning_object
=
learning_object_repository
.
find
params
[
:learning_object_id
]
end
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment