2020-05-14 17:03:09 +02:00
|
|
|
class FileStorage::Request
|
2020-06-06 20:43:14 +02:00
|
|
|
JSONIPC.request PutChunk, 40 do
|
2020-05-14 17:03:09 +02:00
|
|
|
property mid : String # autogenerated
|
|
|
|
property filedigest : String # SHA256 digest of the entire file
|
2020-05-16 01:40:09 +02:00
|
|
|
# Chunk:
|
|
|
|
# - n : Int32 => chunk number
|
|
|
|
# - on : Int32 => number of chunks
|
2020-06-06 20:43:14 +02:00
|
|
|
# - digest : String => digest of the chunk
|
2020-05-14 17:03:09 +02:00
|
|
|
property chunk : Chunk # For now, just the counter in a string
|
|
|
|
property data : String # base64 slice
|
|
|
|
def initialize(file_info : FileInfo, count, bindata)
|
|
|
|
# count: chunk number
|
|
|
|
|
|
|
|
@filedigest = file_info.digest
|
|
|
|
@data = Base64.encode bindata
|
|
|
|
@chunk = FileStorage::Chunk.new count, file_info.nb_chunks - 1, @data
|
|
|
|
@mid = UUID.random.to_s
|
|
|
|
end
|
|
|
|
|
|
|
|
def handle(filestoraged : FileStorage::Service, event : IPC::Event::Events)
|
2020-05-16 01:40:09 +02:00
|
|
|
user = filestoraged.get_logged_user event
|
2020-05-14 17:03:09 +02:00
|
|
|
|
|
|
|
raise Exception.new "unauthorized" if user.nil?
|
|
|
|
|
|
|
|
# FIXME: Maybe this should be moved to FileStorage::Service
|
|
|
|
fd = event.connection.fd
|
|
|
|
|
|
|
|
user_data = filestoraged.get_user_data user.uid
|
|
|
|
|
2020-06-06 20:43:14 +02:00
|
|
|
filestoraged.storage.write_chunk self, user_data
|
2020-05-14 17:03:09 +02:00
|
|
|
rescue e
|
|
|
|
return Response::Error.new @mid, "unauthorized"
|
|
|
|
end
|
|
|
|
end
|
2020-06-06 20:43:14 +02:00
|
|
|
FileStorage.requests << PutChunk
|
2020-05-14 17:03:09 +02:00
|
|
|
|
2020-06-06 20:43:14 +02:00
|
|
|
JSONIPC.request GetChunk, 41 do
|
|
|
|
property mid : String # autogenerated
|
|
|
|
property filedigest : String # SHA256 digest of the entire file
|
|
|
|
property n : Int32 # chunk number
|
2020-05-14 17:03:09 +02:00
|
|
|
|
2020-06-06 20:43:14 +02:00
|
|
|
def initialize(@filedigest, @n)
|
|
|
|
@mid = UUID.random.to_s
|
2020-05-14 17:03:09 +02:00
|
|
|
end
|
|
|
|
|
2020-06-06 20:43:14 +02:00
|
|
|
def handle(filestoraged : FileStorage::Service, event : IPC::Event::Events)
|
|
|
|
user = filestoraged.get_logged_user event
|
|
|
|
|
|
|
|
raise Exception.new "unauthorized" if user.nil?
|
|
|
|
|
|
|
|
# FIXME: Maybe this should be moved to FileStorage::Service
|
|
|
|
fd = event.connection.fd
|
|
|
|
|
|
|
|
user_data = filestoraged.get_user_data user.uid
|
|
|
|
|
|
|
|
filestoraged.storage.read_chunk self, user_data
|
|
|
|
rescue e
|
|
|
|
return Response::Error.new @mid, "unauthorized"
|
|
|
|
end
|
2020-05-14 17:03:09 +02:00
|
|
|
end
|
2020-06-06 20:43:14 +02:00
|
|
|
FileStorage.requests << GetChunk
|
2020-05-14 17:03:09 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
class FileStorage::Response
|
2020-06-06 20:43:14 +02:00
|
|
|
JSONIPC.request PutChunk, 40 do
|
2020-05-14 17:03:09 +02:00
|
|
|
property mid : String
|
2020-05-20 09:49:16 +02:00
|
|
|
property file_digest : String
|
2020-05-20 09:28:06 +02:00
|
|
|
property n : Int32 # chunk number
|
2020-05-20 09:49:16 +02:00
|
|
|
def initialize(@mid, @file_digest, @n)
|
2020-05-14 17:03:09 +02:00
|
|
|
end
|
|
|
|
end
|
2020-06-06 20:43:14 +02:00
|
|
|
|
|
|
|
JSONIPC.request GetChunk, 41 do
|
|
|
|
property mid : String
|
|
|
|
property file_digest : String
|
|
|
|
# Chunk:
|
|
|
|
# - n : Int32 => chunk number
|
|
|
|
# - on : Int32 => number of chunks
|
|
|
|
# - digest : String => digest of the chunk
|
|
|
|
property chunk : Chunk # Currently: info about the chunk
|
|
|
|
property data : String # base64 slice
|
|
|
|
def initialize(@mid, @file_digest, @chunk, @data)
|
|
|
|
end
|
|
|
|
end
|
2020-05-14 17:03:09 +02:00
|
|
|
end
|