cleanup
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python3.12
|
||||
|
||||
import logging
|
||||
from typing import Optional
|
||||
from fastapi import FastAPI, Request, HTTPException
|
||||
from pydantic import BaseModel
|
||||
from aiohttp import ClientSession, ClientTimeout
|
||||
@@ -9,12 +10,10 @@ from .constructors import ValidXCRequest
|
||||
|
||||
class XC(FastAPI):
|
||||
"""XC (CrossComm) Endpoints"""
|
||||
def __init__(self, app: FastAPI, util, constants, glob_state) -> None: # pylint: disable=super-init-not-called
|
||||
def __init__(self, app: FastAPI, util, constants) -> None: # pylint: disable=super-init-not-called
|
||||
self.app = app
|
||||
self.util = util
|
||||
self.constants = constants
|
||||
self.glob_state = glob_state
|
||||
|
||||
|
||||
self.endpoints: dict = {
|
||||
"xc": self.xc_handler,
|
||||
@@ -31,7 +30,7 @@ class XC(FastAPI):
|
||||
key: str = data.key
|
||||
bid: int = data.bid
|
||||
cmd: str = data.cmd
|
||||
cmd_data: dict = data.data
|
||||
cmd_data: Optional[dict] = data.data
|
||||
if not self.util.check_key(path=request.url.path, req_type=0, key=key):
|
||||
raise HTTPException(status_code=403, detail="Unauthorized")
|
||||
|
||||
@@ -50,11 +49,15 @@ class XC(FastAPI):
|
||||
async with ClientSession() as session:
|
||||
async with await session.post(f"{bot_api_url}{cmd}", json=cmd_data, headers={
|
||||
'Content-Type': 'application/json; charset=utf-8'
|
||||
}, timeout=ClientTimeout(connect=5, sock_read=5)) as request:
|
||||
response: dict = await request.json()
|
||||
}, timeout=ClientTimeout(connect=5, sock_read=5)) as aiohttp_request:
|
||||
response: dict = await aiohttp_request.json()
|
||||
return {
|
||||
'success': True,
|
||||
'response': response
|
||||
}
|
||||
except Exception as e:
|
||||
logging.debug("Error: %s", str(e))
|
||||
logging.debug("Error: %s", str(e))
|
||||
return {
|
||||
'err': True,
|
||||
'errorText': 'General error.',
|
||||
}
|
||||
Reference in New Issue
Block a user