2020-05-14 17:03:09 +02:00
|
|
|
|
|
|
|
class FileStorage::Request
|
2020-10-20 19:15:50 +02:00
|
|
|
IPC::JSON.message Upload, 20 do
|
2020-05-14 17:03:09 +02:00
|
|
|
property mid : String # autogenerated
|
|
|
|
property file : FileInfo
|
|
|
|
def initialize(@file : FileInfo)
|
|
|
|
@mid = UUID.random.to_s
|
|
|
|
end
|
|
|
|
|
2023-02-09 23:28:10 +01:00
|
|
|
def handle(filestoraged : FileStorage::Service, event : IPC::Event)
|
2020-05-16 01:40:09 +02:00
|
|
|
user = filestoraged.get_logged_user event
|
2020-05-14 17:03:09 +02:00
|
|
|
|
2020-10-20 23:57:37 +02:00
|
|
|
raise NotLoggedException.new if user.nil?
|
2020-05-14 17:03:09 +02:00
|
|
|
|
2020-10-22 01:21:44 +02:00
|
|
|
raise FileTooBig.new if @file.size > filestoraged.max_file_size
|
|
|
|
|
2020-05-14 17:03:09 +02:00
|
|
|
# FIXME: Maybe this should be moved to FileStorage::Service
|
2020-07-18 16:35:35 +02:00
|
|
|
fd = event.fd
|
2020-05-14 17:03:09 +02:00
|
|
|
|
|
|
|
user_data = filestoraged.get_user_data user.uid
|
|
|
|
|
2020-05-16 01:40:09 +02:00
|
|
|
filestoraged.storage.upload self, user_data
|
2020-05-14 17:03:09 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
FileStorage.requests << Upload
|
|
|
|
end
|
|
|
|
|
|
|
|
class FileStorage::Response
|
2020-10-20 19:15:50 +02:00
|
|
|
IPC::JSON.message Upload, 20 do
|
2020-05-14 17:03:09 +02:00
|
|
|
property mid : String
|
2020-05-20 09:20:52 +02:00
|
|
|
property path : String
|
|
|
|
def initialize(@mid, @path)
|
2020-05-14 17:03:09 +02:00
|
|
|
end
|
|
|
|
end
|
2020-06-06 20:43:14 +02:00
|
|
|
FileStorage.responses << Upload
|
2020-05-14 17:03:09 +02:00
|
|
|
|
2020-10-20 19:15:50 +02:00
|
|
|
# IPC::JSON.message Responses, 100 do
|
2020-05-16 01:40:09 +02:00
|
|
|
# property mid : String
|
2020-06-06 20:43:14 +02:00
|
|
|
# property responses : Array(Response | Errors) # a response for each request
|
2020-05-16 01:40:09 +02:00
|
|
|
# property response : String
|
|
|
|
# property reason : String?
|
|
|
|
#
|
|
|
|
# def initialize(@mid, @response, @responses, @reason = nil)
|
|
|
|
# end
|
|
|
|
# end
|
2020-05-14 17:03:09 +02:00
|
|
|
end
|