parent
42d1fdffc4
commit
da02f3e69f
@ -0,0 +1,44 @@
|
||||
from sanic import Blueprint, Request, json, Sanic
|
||||
from sanic.log import logger
|
||||
|
||||
import time
|
||||
|
||||
from .common import common_api
|
||||
|
||||
|
||||
|
||||
bp_sif_api = Blueprint("sif_api")
|
||||
|
||||
|
||||
|
||||
@bp_sif_api.route("/api", methods=["POST"])
|
||||
@common_api
|
||||
async def api(request: Request):
|
||||
api_list = request.ctx.request_data
|
||||
logger.debug(f"{api_list=}")
|
||||
|
||||
api_resp = []
|
||||
route_dict = {}
|
||||
for route in Sanic.get_app().router.routes:
|
||||
route_dict[route.path] = route.handler
|
||||
|
||||
for api_request in api_list:
|
||||
module, action = api_request["module"], api_request["action"]
|
||||
handler = route_dict.get(f"main.php/{module}/{action}", None)
|
||||
if handler:
|
||||
result = await handler.__wrapped__(request)
|
||||
logger.debug(f"api:main.php/{module}/{action} {result=}")
|
||||
else:
|
||||
logger.error(f"api:main.php/{module}/{action} not found")
|
||||
result = {}
|
||||
api_resp.append({
|
||||
"commandNum": False,
|
||||
"result": result,
|
||||
"status": 200,
|
||||
"timeStamp": int(time.time())
|
||||
})
|
||||
|
||||
return api_resp
|
||||
|
||||
|
||||
|
Loading…
Reference in new issue