New API.
parent
86495365d6
commit
aec3445771
|
@ -12,7 +12,7 @@ class FileStorage::Request
|
|||
def handle(filestoraged : FileStorage::Service, event : IPC::Event::Events)
|
||||
user = filestoraged.get_logged_user event
|
||||
|
||||
return Errors::Authorization.new @mid if user.nil?
|
||||
raise NotLoggedException.new if user.nil?
|
||||
|
||||
# FIXME: Maybe this should be moved to FileStorage::Service
|
||||
fd = event.fd
|
||||
|
@ -20,8 +20,6 @@ class FileStorage::Request
|
|||
user_data = filestoraged.get_user_data user.uid
|
||||
|
||||
filestoraged.storage.download self, user_data
|
||||
rescue e
|
||||
return Errors::GenericError.new @mid, e.to_s
|
||||
end
|
||||
end
|
||||
FileStorage.requests << Download
|
||||
|
|
|
@ -25,9 +25,7 @@ class FileStorage::Request
|
|||
|
||||
user_data = filestoraged.get_user_data user.uid
|
||||
|
||||
return Response::Login.new @mid
|
||||
rescue e
|
||||
return Errors::GenericError.new @mid, "unauthorized"
|
||||
Response::Login.new @mid
|
||||
end
|
||||
end
|
||||
FileStorage.requests << Login
|
||||
|
|
|
@ -20,18 +20,16 @@ class FileStorage::Request
|
|||
def handle(filestoraged : FileStorage::Service, event : IPC::Event::Events)
|
||||
user = filestoraged.get_logged_user event
|
||||
|
||||
return Errors::Authorization.new @mid if user.nil?
|
||||
raise NotLoggedException.new if user.nil?
|
||||
|
||||
# FIXME: Maybe this should be moved to FileStorage::Service
|
||||
fd = event.fd
|
||||
|
||||
user_data = filestoraged.get_user_data user.uid
|
||||
|
||||
Baguette::Log.info "PutChunk request: #{@mid}, file #{@filedigest}, chunk: n=#{@chunk.n}, on=#{@chunk.on}, digest=#{@chunk.digest}"
|
||||
Baguette::Log.debug "PutChunk request: #{@mid}, file #{@filedigest}, chunk: n=#{@chunk.n}, on=#{@chunk.on}, digest=#{@chunk.digest}"
|
||||
|
||||
filestoraged.storage.write_chunk self, user_data
|
||||
rescue e
|
||||
return Errors::GenericError.new @mid, e.to_s
|
||||
end
|
||||
end
|
||||
FileStorage.requests << PutChunk
|
||||
|
@ -48,16 +46,16 @@ class FileStorage::Request
|
|||
def handle(filestoraged : FileStorage::Service, event : IPC::Event::Events)
|
||||
user = filestoraged.get_logged_user event
|
||||
|
||||
return Errors::Authorization.new @mid if user.nil?
|
||||
raise NotLoggedException.new if user.nil?
|
||||
|
||||
# FIXME: Maybe this should be moved to FileStorage::Service
|
||||
fd = event.fd
|
||||
|
||||
user_data = filestoraged.get_user_data user.uid
|
||||
|
||||
Baguette::Log.debug "PutChunk request: #{@mid}, file #{@filedigest}, chunk: n=#{@n}"
|
||||
|
||||
filestoraged.storage.read_chunk self, user_data
|
||||
rescue e
|
||||
return Errors::GenericError.new @mid, e.to_s
|
||||
end
|
||||
end
|
||||
FileStorage.requests << GetChunk
|
||||
|
|
|
@ -10,7 +10,7 @@ class FileStorage::Request
|
|||
def handle(filestoraged : FileStorage::Service, event : IPC::Event::Events)
|
||||
user = filestoraged.get_logged_user event
|
||||
|
||||
return Errors::Authorization.new @mid if user.nil?
|
||||
raise NotLoggedException.new if user.nil?
|
||||
|
||||
# FIXME: Maybe this should be moved to FileStorage::Service
|
||||
fd = event.fd
|
||||
|
@ -18,8 +18,6 @@ class FileStorage::Request
|
|||
user_data = filestoraged.get_user_data user.uid
|
||||
|
||||
filestoraged.storage.upload self, user_data
|
||||
rescue e
|
||||
return Errors::GenericError.new @mid, e.to_s
|
||||
end
|
||||
end
|
||||
FileStorage.requests << Upload
|
||||
|
|
|
@ -116,20 +116,20 @@ class FileStorage::Service < IPC::Server
|
|||
|
||||
request_id = "#{request.id}"
|
||||
|
||||
begin
|
||||
response = request.handle self, event
|
||||
response = begin
|
||||
request.handle self, event
|
||||
rescue e : AuthorizationException
|
||||
Baguette::Log.error "#{request_name} authorization error"
|
||||
response = FileStorage::Errors::GenericError.new request_id, "authorization error"
|
||||
Baguette::Log.warning "#{request_name} authorization error"
|
||||
Errors::Authorization.new request_id
|
||||
rescue e : AdminAuthorizationException
|
||||
Baguette::Log.error "#{request_name} no admin authorization"
|
||||
response = FileStorage::Errors::GenericError.new request_id, "admin authorization error"
|
||||
Baguette::Log.warning "#{request_name} no admin authorization"
|
||||
Errors::Authorization.new request_id
|
||||
rescue e : NotLoggedException
|
||||
Baguette::Log.error "#{request_name} user not logged"
|
||||
response = FileStorage::Errors::GenericError.new request_id, "user not logged"
|
||||
# Do not handle generic exception case: do not provide a response.
|
||||
# rescue e # Generic case
|
||||
# Baguette::Log.error "#{request_name} generic error #{e}"
|
||||
Baguette::Log.warning "#{request_name} user not logged"
|
||||
Errors::GenericError.new request_id, "user not logged"
|
||||
rescue e
|
||||
Baguette::Log.error "#{request_name} generic error #{e}"
|
||||
Errors::GenericError.new request_id, "unexpected error"
|
||||
end
|
||||
|
||||
# If clients sent requests with an “id” field, it is copied
|
||||
|
|
Loading…
Reference in New Issue