properly run message processor
This commit is contained in:
parent
e21546b7a6
commit
22d0ed0b9a
|
@ -24,7 +24,8 @@ class ProcessData:
|
|||
|
||||
|
||||
async def __call__(self):
|
||||
return await getattr(self, f'cmd_{self.type}')()
|
||||
logging.verbose(f'Handling object of type "{self.type}"')
|
||||
return getattr(self, f'cmd_{self.type}')()
|
||||
|
||||
|
||||
def valid_type(self):
|
||||
|
@ -34,7 +35,7 @@ class ProcessData:
|
|||
return False
|
||||
|
||||
|
||||
async def cmd_follow(self):
|
||||
def cmd_follow(self):
|
||||
if self.actor.type.lower() != 'application':
|
||||
#return self.response.json('No', status=403)
|
||||
|
||||
|
@ -69,7 +70,7 @@ class ProcessData:
|
|||
logging.verbose(f'Instance joined the relay: {self.instance.domain}')
|
||||
|
||||
|
||||
async def cmd_undo(self):
|
||||
def cmd_undo(self):
|
||||
if self.actor.type.lower() != 'application':
|
||||
return
|
||||
|
||||
|
@ -83,7 +84,7 @@ class ProcessData:
|
|||
logging.debug(f'Removed instance from relay: {self.instance.domain}')
|
||||
|
||||
|
||||
async def cmd_announce(self):
|
||||
def cmd_announce(self):
|
||||
if isinstance(self.data.object, dict):
|
||||
object = self.data.object
|
||||
object_id = self.data.object.id
|
||||
|
@ -126,7 +127,7 @@ class ProcessData:
|
|||
logging.debug(f'Server error {response.status}: {response.text}')
|
||||
|
||||
|
||||
async def cmd_create(self):
|
||||
def cmd_create(self):
|
||||
return self.cmd_announce()
|
||||
|
||||
|
||||
|
|
|
@ -136,9 +136,11 @@ class UnciaActor(View):
|
|||
processor = ProcessData(request, response, request.data.json)
|
||||
|
||||
if not processor.valid_type():
|
||||
return processor.error(f'Message type unhandled: {processor.type}', 401)
|
||||
return response.json({'error': f'Message type unhandled: {processor.type}'}, status=401)
|
||||
|
||||
loop = asyncio.get_running_loop()
|
||||
loop.create_task(processor())
|
||||
|
||||
asyncio.ensure_future(processor())
|
||||
return response.text('UvU', status=202)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue