-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
38 lines (30 loc) · 1.12 KB
/
main.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
import os
from importlib import import_module
from fastapi import FastAPI
from routes import auth, anime
from database import create_pool
from template import router as template_router
app = FastAPI()
app.include_router(auth.router)
app.include_router(anime.router)
app.include_router(template_router)
# 加载插件
plugins_dir = "plugins"
if os.path.isdir(plugins_dir):
for plugin_name in os.listdir(plugins_dir):
plugin_path = os.path.join(plugins_dir, plugin_name)
if os.path.isdir(plugin_path):
try:
plugin_module = import_module(f"plugins.{plugin_name}.main")
if hasattr(plugin_module, "router"):
app.include_router(plugin_module.router)
else:
print(f"Plugin {plugin_name} does not have a router.")
except ImportError:
print(f"Failed to import plugin {plugin_name}.")
@app.on_event("startup")
async def startup():
await create_pool()
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8080, reload=False)