next_chunk in errors (FileExists, ChunkAlreadyUploaded), FileFullyUploaded.
This commit is contained in:
parent
854f383172
commit
c926e5334a
@ -43,8 +43,9 @@ class FileStorage::Errors
|
|||||||
property mid : String
|
property mid : String
|
||||||
property reason = "file already present"
|
property reason = "file already present"
|
||||||
property filedigest : String
|
property filedigest : String
|
||||||
|
property next_chunk : Int32
|
||||||
|
|
||||||
def initialize(@mid, @filedigest)
|
def initialize(@mid, @filedigest, @next_chunk)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
FileStorage.errors << FileExists
|
FileStorage.errors << FileExists
|
||||||
@ -59,4 +60,15 @@ class FileStorage::Errors
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
FileStorage.errors << FileDoesNotExist
|
FileStorage.errors << FileDoesNotExist
|
||||||
|
|
||||||
|
# When a file was already fully uploaded.
|
||||||
|
JSONIPC.request FileFullyUploaded, 206 do
|
||||||
|
property mid : String
|
||||||
|
property reason = "file already uploaded fully"
|
||||||
|
property filedigest : String
|
||||||
|
|
||||||
|
def initialize(@mid, @filedigest)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
FileStorage.errors << FileFullyUploaded
|
||||||
end
|
end
|
||||||
|
@ -105,9 +105,14 @@ class FileStorage::Storage
|
|||||||
if transfer_info.chunks.select do |v| v == chunk_number end.size == 1
|
if transfer_info.chunks.select do |v| v == chunk_number end.size == 1
|
||||||
write_a_chunk file_digest, chunk_size, chunk_number, data
|
write_a_chunk file_digest, chunk_size, chunk_number, data
|
||||||
else
|
else
|
||||||
|
begin
|
||||||
# Send the next remaining chunk to upload.
|
# Send the next remaining chunk to upload.
|
||||||
next_chunk = transfer_info.chunks.sort.first
|
next_chunk = transfer_info.chunks.sort.first
|
||||||
return FileStorage::Errors::ChunkAlreadyUploaded.new mid, file_digest, next_chunk
|
return FileStorage::Errors::ChunkAlreadyUploaded.new mid, file_digest, next_chunk
|
||||||
|
rescue e : IndexError
|
||||||
|
# In case the file was completely uploaded already.
|
||||||
|
return FileStorage::Errors::FileFullyUploaded.new mid, file_digest
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
remove_chunk_from_db transfer_info, chunk_number
|
remove_chunk_from_db transfer_info, chunk_number
|
||||||
@ -185,7 +190,13 @@ class FileStorage::Storage
|
|||||||
else
|
else
|
||||||
# File information already exists, request may be duplicated,
|
# File information already exists, request may be duplicated,
|
||||||
# in this case: ignore the upload request.
|
# in this case: ignore the upload request.
|
||||||
return FileStorage::Errors::FileExists.new mid, file_digest
|
begin
|
||||||
|
next_chunk = transfer_info.chunks.sort.first
|
||||||
|
return FileStorage::Errors::FileExists.new mid, file_digest, next_chunk
|
||||||
|
rescue e : IndexError
|
||||||
|
# In case the file was completely uploaded already.
|
||||||
|
return FileStorage::Errors::FileFullyUploaded.new mid, file_digest
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO: store upload request in UserData?
|
# TODO: store upload request in UserData?
|
||||||
|
Loading…
Reference in New Issue
Block a user