upload is ok

dev
Philippe PITTOLI 2020-01-30 19:17:28 +01:00
parent 8c0a7b1f14
commit a9aea04a27
2 changed files with 22 additions and 6 deletions

View File

@ -60,7 +60,7 @@ def hdl_upload(request : FileStorage::UploadRequest, user : User) : FileStorage:
# TODO: verify the rights and quotas of the user
# First: check if the file already exists
transfer_info = Context.db_by_filedigest.get request.file.digest
transfer_info = Context.db_by_filedigest.get? request.file.digest
if transfer_info.nil?
# In case file informations aren't already registered
# which is normal at this point

View File

@ -2,12 +2,15 @@ require "../common/filestorage.cr"
require "ipc"
require "option_parser"
require "../common/utils.cr"
require "../server/context.cr"
filename = "./README.md"
tags = "readme example"
chunk_number_to_remove = 1
OptionParser.parse do |parser|
parser.on "-f file-to-transfer",
"--file to-transfer",
@ -15,6 +18,12 @@ OptionParser.parse do |parser|
filename = opt
end
parser.on "-c chunk_number_to_remove",
"--chunk-number chunk_number_to_remove",
"Once the upload stard, we remove chunks. This test the removal of one of them in the DB." do |opt|
chunk_number_to_remove = opt.to_i
end
parser.on "-d database-directory",
"--db-dir directory",
"DB directory" do |opt|
@ -29,24 +38,31 @@ OptionParser.parse do |parser|
end
parser.unknown_args do |args|
pp! args
pp! args if args.size > 0
end
end
pp! Context
fileinfo : FileStorage::FileInfo? = nil
File.open(filename) do |file|
fileinfo = FileStorage::FileInfo.new file, tags.split(' ')
end
pp! fileinfo
transfer_info = TransferInfo.new 1000, fileinfo.not_nil!
puts "transfer info of the file #{filename}"
puts
pp! transfer_info
puts
puts "store file info then remove a chunk (number #{chunk_number_to_remove})"
puts
Context.db << transfer_info
# remove the chunk once the information is recorded in the db
remove_chunk_from_db transfer_info, chunk_number_to_remove
Context.db.each do |ti|
pp! ti
end