81 lines
2.4 KiB
Crystal
81 lines
2.4 KiB
Crystal
|
|
||
|
# We verify the user's rights to upload files.
|
||
|
# TODO RIGHTS
|
||
|
# if user wants to upload but not allowed to: Response
|
||
|
# if user wants to get a file but not allowed to: Response
|
||
|
|
||
|
# The user is authorized to upload files.
|
||
|
|
||
|
# TODO: quotas
|
||
|
# Quotas are not defined yet.
|
||
|
|
||
|
#class FileStorage::Request
|
||
|
# JSONIPC.request Authentication, 10 do
|
||
|
# property mid : String # autogenerated
|
||
|
# property token : Token
|
||
|
# property uploads : Array(UploadRequest)?
|
||
|
# property downloads : Array(DownloadRequest)?
|
||
|
#
|
||
|
# def initialize(@token, @uploads = nil, @downloads = nil)
|
||
|
# @mid = UUID.random.to_s
|
||
|
# end
|
||
|
#
|
||
|
# # Store the client in connected_users and users_status.
|
||
|
# # If already in users_status:
|
||
|
# # check if the requests are the same
|
||
|
# # if not: add them to the user structure in users_status
|
||
|
# def handle(filestoraged : FileStorage::Service, event : IPC::Event::Events)
|
||
|
#
|
||
|
# token = filestoraged.auth.decode_token @token
|
||
|
# userid = token.uid
|
||
|
#
|
||
|
# puts "user authentication: #{userid}"
|
||
|
#
|
||
|
# # Is the user already recorded in users_status?
|
||
|
# if filestoraged.users_status[userid]?
|
||
|
# puts "We already knew this user"
|
||
|
#
|
||
|
# filestoraged.connected_users[event.connection.fd] = userid
|
||
|
# # TODO
|
||
|
# pp! filestoraged.connected_users
|
||
|
# pp! filestoraged.users_status[userid]
|
||
|
#
|
||
|
# # Let's ignore this error, just continue.
|
||
|
# # It could have been a network error, for example.
|
||
|
# # return FileStorage::Response::Error.new @mid, "user already connected"
|
||
|
# else
|
||
|
# # AuthenticationMessage includes requests.
|
||
|
# new_user = User.new token, @uploads, @downloads
|
||
|
#
|
||
|
# filestoraged.connected_users[event.connection.fd] = userid
|
||
|
#
|
||
|
# # record the new user in users_status
|
||
|
# filestoraged.users_status[userid] = new_user
|
||
|
#
|
||
|
# puts "New user is: #{new_user.token.login}"
|
||
|
# end
|
||
|
#
|
||
|
# # The user is now connected.
|
||
|
# user = filestoraged.users_status[userid]
|
||
|
#
|
||
|
# responses = filestoraged.storage.requests [ @uploads, @downloads ].flatten,
|
||
|
# filestoraged.users_status[userid],
|
||
|
# event
|
||
|
#
|
||
|
# # Sending a response, containing a response for each request.
|
||
|
# FileStorage::Response::Success.new @mid, responses
|
||
|
# end
|
||
|
# end
|
||
|
# FileStorage.requests << Authentication
|
||
|
#end
|
||
|
#
|
||
|
#class FileStorage::Response
|
||
|
# JSONIPC.request AuthenticationSuccess, 10 do
|
||
|
# property mid : String
|
||
|
# property responses : Array(FileStorage::Response)
|
||
|
# def initialize(@mid, @responses)
|
||
|
# end
|
||
|
# end
|
||
|
#end
|
||
|
|