This repository has been archived by the owner on Dec 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
66 lines (56 loc) · 2.17 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from importlib import util
from os import path
from glob import glob
from fastapi import APIRouter, Request
from typing import Optional
routers = []
for module_path in [
f
for f in glob(path.join(path.dirname(__file__), "**/*.py"), recursive=True)
if path.basename(f) != "__init__.py"
]:
spec = util.spec_from_file_location("", module_path)
module = util.module_from_spec(spec)
spec.loader.exec_module(module)
router = getattr(module, "router", None)
if router is not None:
routers.append(router)
if path.basename(module_path) != "api.py":
for obj in dir(module):
globals()[obj] = module.__dict__[obj]
router = APIRouter(tags=["slashless_forwarder"])
@router.post("/fwdr")
async def forward_slashless(
request: Request,
model: Optional[str] = None,
f: Optional[str] = None,
module: Optional[str] = None,
method: Optional[str] = None,
):
if f != None:
module, method = f.split(".")
try:
find_response = globals()[f"{module}_{method}".lower()]
return await find_response(request)
except KeyError:
try:
game_code = model.split(":")[0]
# TODO: check for more edge cases
if game_code == "MDX" and module == "eventlog" or module == "eventlog_2":
find_response = globals()[f"ddr_{module}_{method}"]
elif game_code == "REC":
find_response = globals()[f"drs_{module}_{method}"]
elif game_code == "KFC" and module == "eventlog":
find_response = globals()[f"sdvx_{module}_{method}"]
elif game_code == "M32":
if module == "lobby":
find_response = globals()[f"gitadora_{module}_{method}"]
else:
gd_module = module.split("_")
find_response = globals()[f"gitadora_{gd_module[-1]}_{method}"]
return await find_response(gd_module[0], request)
return await find_response(request)
except (KeyError, UnboundLocalError):
print("Try URL Slash 1 (On) if this game is supported.")
return Response(status_code=404)
routers.append(router)