Skip to content
Snippets Groups Projects
Commit cc0e195f authored by Mauricio Giacomini Girardello's avatar Mauricio Giacomini Girardello
Browse files

refactoring and fixing some chunks issues

parent a2f84bfd
No related branches found
No related tags found
No related merge requests found
...@@ -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[:resumableChunkNumber] chunk = resumable_chunk chunk_number
#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)
publisher.post @learning_object, resumable_filename post_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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment