Init
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
from ..Convention.Runtime.Config import *
|
||||
from ..Convention.Runtime.GlobalConfig import ProjectConfig, ConsoleFrontColor
|
||||
from ..CoreModules.flags import set_internal_verbose
|
||||
from ..CoreModules.flags import set_internal_verbose, get_internal_debug
|
||||
from .web import app
|
||||
from argparse import ArgumentParser
|
||||
from typing import *
|
||||
import sys
|
||||
try:
|
||||
import uvicorn
|
||||
except ImportError as ex:
|
||||
ImportingThrow(ex, "Internal", ["uvicorn"])
|
||||
|
||||
def main() -> int:
|
||||
config = ProjectConfig()
|
||||
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument("--main-webhook-url", type=str, default=config.FindItem("main_webhook_url", ""))
|
||||
parser.add_argument("--host", type=str, default=config.FindItem("host", "0.0.0.0"))
|
||||
parser.add_argument("--port", type=int, default=config.FindItem("port", 8000))
|
||||
parser.add_argument("--verbose", type=bool, default=config.FindItem("verbose", False))
|
||||
@@ -22,17 +25,6 @@ def main() -> int:
|
||||
parser.print_help()
|
||||
return 0
|
||||
|
||||
# region Main Webhook URL
|
||||
|
||||
webhook_url = args.main_webhook_url
|
||||
if not webhook_url or webhook_url == "":
|
||||
config.Log("Fatal", f"{ConsoleFrontColor.RED}Main webhook URL is not set{ConsoleFrontColor.RESET}")
|
||||
return 1
|
||||
|
||||
config.Log("Info", f"{ConsoleFrontColor.GREEN}Main webhook URL: {webhook_url}{ConsoleFrontColor.RESET}")
|
||||
|
||||
# endregion Main Webhook URL
|
||||
|
||||
# region Verbose
|
||||
|
||||
verbose = args.verbose
|
||||
|
||||
@@ -4,7 +4,7 @@ from fastapi.responses import JSONResponse
|
||||
from contextlib import asynccontextmanager
|
||||
from ..CoreModules.middleware import ConcurrencyLimitMiddleware
|
||||
from ..CoreModules.plugin_interface import ImportPlugins
|
||||
from ..CoreRouters import callback, health, private
|
||||
from ..CoreRouters import callback, health
|
||||
from ..Convention.Runtime.GlobalConfig import *
|
||||
from ..Convention.Runtime.Architecture import Architecture
|
||||
|
||||
@@ -46,8 +46,7 @@ def generate_app(APP_CONFIG: dict) -> FastAPI:
|
||||
# 注册路由
|
||||
app.include_router(callback.router, prefix="/api", tags=["callback"])
|
||||
app.include_router(health.router, tags=["health"])
|
||||
app.include_router(private.router, prefix="/api", tags=["private"])
|
||||
ImportPlugins(app, config.FindItem("plugin_dir", "Plugins"))
|
||||
ImportPlugins(app, config.FindItem("plugin_dir", "Plugins/"))
|
||||
|
||||
# 注册至框架中
|
||||
Architecture.Register(FastAPI, app, lambda: None)
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
{
|
||||
"properties": {},
|
||||
"find": {
|
||||
"main_webhook_url": ""
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,9 @@ import sqlite3
|
||||
import json
|
||||
import time
|
||||
from typing import *
|
||||
from Convention.Runtime.GlobalConfig import ProjectConfig, ConsoleFrontColor
|
||||
from Convention.Runtime.Architecture import Architecture
|
||||
from Convention.Runtime.File import ToolFile
|
||||
from ..Convention.Runtime.GlobalConfig import ProjectConfig, ConsoleFrontColor
|
||||
from ..Convention.Runtime.Architecture import Architecture
|
||||
from ..Convention.Runtime.File import ToolFile
|
||||
|
||||
config = ProjectConfig()
|
||||
DATABASE_PATH = config.GetFile(config.FindItem("database_path", "db.db"), False).GetFullPath()
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
from ..Convention.Runtime.Architecture import *
|
||||
from ..Convention.Runtime.GlobalConfig import ProjectConfig
|
||||
from pydantic import *
|
||||
|
||||
config = ProjectConfig()
|
||||
|
||||
class DebugFlags(BaseModel):
|
||||
debug: bool = Field(default=False)
|
||||
|
||||
class VerboseFlags(BaseModel):
|
||||
verbose: bool = Field(default=False)
|
||||
|
||||
Architecture.Register(DebugFlags, DebugFlags(debug=False), lambda: None)
|
||||
Architecture.Register(DebugFlags, DebugFlags(debug=config.FindItem("debug", False)), lambda: None)
|
||||
Architecture.Register(VerboseFlags, VerboseFlags(verbose=False), lambda: None)
|
||||
|
||||
def set_internal_debug(debug:bool) -> None:
|
||||
@@ -20,4 +23,6 @@ def set_internal_verbose(verbose:bool) -> None:
|
||||
def get_internal_verbose() -> bool:
|
||||
return Architecture.Get(VerboseFlags).verbose
|
||||
|
||||
config.SaveProperties()
|
||||
|
||||
__all__ = ["set_internal_debug", "get_internal_debug", "set_internal_verbose", "get_internal_verbose"]
|
||||
@@ -1,5 +1,6 @@
|
||||
from ..Convention.Runtime.GlobalConfig import ProjectConfig
|
||||
from ..Convention.Runtime.Architecture import Architecture
|
||||
from ..Convention.Runtime.File import ToolFile
|
||||
from ..CoreModules.database import get_db
|
||||
from fastapi import APIRouter, FastAPI
|
||||
from typing import *
|
||||
@@ -82,7 +83,7 @@ class PluginInterface(ABC):
|
||||
'''
|
||||
return DatabaseModel()
|
||||
|
||||
def ImportPlugins(app: FastAPI, plugin_dir:str = "Plugins") -> None:
|
||||
def ImportPlugins(app: FastAPI, plugin_dir:str = "Plugins/") -> None:
|
||||
'''
|
||||
导入插件
|
||||
|
||||
@@ -90,7 +91,14 @@ def ImportPlugins(app: FastAPI, plugin_dir:str = "Plugins") -> None:
|
||||
app: FastAPI应用
|
||||
plugin_dir: 插件目录
|
||||
'''
|
||||
for file in os.listdir(plugin_dir):
|
||||
plugin_tool_dir = ToolFile(plugin_dir)
|
||||
if plugin_tool_dir.Exists() == False:
|
||||
plugin_tool_dir.MustExistsPath()
|
||||
return
|
||||
if plugin_tool_dir.IsDir() == False:
|
||||
config.Log("Error", f"插件目录不是目录: {plugin_tool_dir.GetFullPath()}")
|
||||
return
|
||||
for file in plugin_tool_dir.DirIter():
|
||||
if file.endswith(".py") and not file.startswith("__"):
|
||||
module_name = file[:-3]
|
||||
try:
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
"""健康检查路由"""
|
||||
from ..Convention.Runtime.Config import *
|
||||
try:
|
||||
import psutil
|
||||
except ImportError:
|
||||
InternalImportingThrow("Internal", ["psutil"])
|
||||
import os
|
||||
from fastapi import APIRouter
|
||||
from fastapi.responses import JSONResponse
|
||||
from CoreModules.database import get_db
|
||||
from Convention.Runtime.GlobalConfig import ProjectConfig, ConsoleFrontColor
|
||||
from ..CoreModules.database import get_db
|
||||
from ..Convention.Runtime.GlobalConfig import ProjectConfig, ConsoleFrontColor
|
||||
|
||||
config = ProjectConfig()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user