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
cc0e195f
Commit
cc0e195f
authored
9 years ago
by
Mauricio Giacomini Girardello
Browse files
Options
Downloads
Patches
Plain Diff
refactoring and fixing some chunks issues
parent
a2f84bfd
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
+27
-13
27 additions, 13 deletions
app/controllers/chunks_controller.rb
with
27 additions
and
13 deletions
app/controllers/chunks_controller.rb
+
27
−
13
View file @
cc0e195f
...
@@ -5,12 +5,10 @@ class ChunksController < ApplicationController
...
@@ -5,12 +5,10 @@ class ChunksController < ApplicationController
#GET /chunk
#GET /chunk
def
show
def
show
#chunk folder path based on the parameters
chunk
=
resumable_chunk
params
[
:resumableChunkNumber
]
dir
=
"/tmp/
#{
params
[
:resumableIdentifier
]
}
"
#chunk path based on the parameters
chunk
=
"
#{
dir
}
/
#{
params
[
:resumableFilename
]
}
.part
#{
params
[
:resumableChunkNumber
]
}
"
if
File
.
exists?
(
chunk
)
if
File
.
exists?
(
chunk
)
post_file_and_create_thumbnail
@learning_object
,
resumable_filename
if
last_chunk?
#Let resumable.js know this chunk already exists
#Let resumable.js know this chunk already exists
render
:nothing
=>
true
,
:status
=>
200
render
:nothing
=>
true
,
:status
=>
200
else
else
...
@@ -23,7 +21,7 @@ class ChunksController < ApplicationController
...
@@ -23,7 +21,7 @@ class ChunksController < ApplicationController
#POST /chunk
#POST /chunk
def
create
def
create
#chunk path based on the parameters
#chunk path based on the parameters
chunk
=
resumable_chunk
params
[
:resumableC
hunk
N
umber
]
chunk
=
resumable_chunk
c
hunk
_n
umber
#Create chunks directory when not present on system
#Create chunks directory when not present on system
if
!
File
.
directory?
(
dir
)
if
!
File
.
directory?
(
dir
)
...
@@ -34,13 +32,8 @@ class ChunksController < ApplicationController
...
@@ -34,13 +32,8 @@ class ChunksController < ApplicationController
FileUtils
.
mv
params
[
:file
].
tempfile
,
chunk
FileUtils
.
mv
params
[
:file
].
tempfile
,
chunk
#Concatenate all the partial files into the original file
#Concatenate all the partial files into the original file
currentSize
=
params
[
:resumableChunkNumber
].
to_i
*
params
[
:resumableChunkSize
].
to_i
filesize
=
params
[
:resumableTotalSize
].
to_i
#When all chunks are uploaded
#When all chunks are uploaded
if
params
[
:resumableChunkNumber
].
to_i
>=
params
[
:resumableTotalChunks
].
to_i
if
last_chunk?
#Create a target file
#Create a target file
File
.
open
(
resumable_filename
,
"a"
)
do
|
target
|
File
.
open
(
resumable_filename
,
"a"
)
do
|
target
|
#Loop trough the chunks
#Loop trough the chunks
...
@@ -58,8 +51,8 @@ class ChunksController < ApplicationController
...
@@ -58,8 +51,8 @@ class ChunksController < ApplicationController
end
end
puts
"File saved to
#{
resumable_filename
}
"
puts
"File saved to
#{
resumable_filename
}
"
end
end
publisher
=
LearningObjectPublisher
.
new
(
DspaceService
.
create_client
)
p
ublisher
.
post
@learning_object
,
resumable_filename
p
ost_file_and_create_thumbnail
@learning_object
,
resumable_filename
end
end
render
nothing:
true
,
status:
200
render
nothing:
true
,
status:
200
...
@@ -67,6 +60,27 @@ class ChunksController < ApplicationController
...
@@ -67,6 +60,27 @@ class ChunksController < ApplicationController
private
private
def
post_file_and_create_thumbnail
(
learning_object
,
filename
)
publisher
=
LearningObjectPublisher
.
new
(
DspaceService
.
create_client
)
publisher
.
post
learning_object
,
filename
end
def
last_chunk?
chunk_number
==
total_chunks
end
def
chunk_size
params
[
:resumableChunkSize
].
to_i
end
def
total_chunks
params
[
:resumableTotalChunks
].
to_i
end
def
chunk_number
params
[
:resumableChunkNumber
].
to_i
end
def
resumable_chunk
(
part
)
def
resumable_chunk
(
part
)
"
#{
resumable_filename
}
.part
#{
part
}
"
"
#{
resumable_filename
}
.part
#{
part
}
"
end
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