You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
import time
|
|
|
|
|
|
|
|
from sanic import Blueprint, Request, Sanic, json
|
|
|
|
from sanic.log import logger
|
|
|
|
|
|
|
|
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:
|
|
|
|
result = {}
|
|
|
|
logger.error(f"api:main.php/{module}/{action} not found")
|
|
|
|
api_resp.append({
|
|
|
|
"commandNum": False,
|
|
|
|
"result": result,
|
|
|
|
"status": 200,
|
|
|
|
"timeStamp": int(time.time())
|
|
|
|
})
|
|
|
|
|
|
|
|
return api_resp
|
|
|
|
|
|
|
|
|
|
|
|
|