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

refactoring chunks controller

parent d8a94e8b
No related branches found
No related tags found
No related merge requests found
......@@ -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[:resumableFilename]}", "a") do |target|
File.open(resumable_filename, "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
......
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