feat: 添加基建配置文件设置接口
This commit is contained in:
@@ -205,3 +205,20 @@ async def reorder_user(user: UserReorderIn = Body(...)) -> OutBase:
|
||||
code=500, status="error", message=f"{type(e).__name__}: {str(e)}"
|
||||
)
|
||||
return OutBase()
|
||||
|
||||
|
||||
@router.post(
|
||||
"/user/infrastructure",
|
||||
summary="导入基建配置文件",
|
||||
response_model=OutBase,
|
||||
status_code=200,
|
||||
)
|
||||
async def import_infrastructure(user: UserSetIn = Body(...)) -> OutBase:
|
||||
|
||||
try:
|
||||
await Config.set_infrastructure(user.scriptId, user.userId, user.jsonFile)
|
||||
except Exception as e:
|
||||
return OutBase(
|
||||
code=500, status="error", message=f"{type(e).__name__}: {str(e)}"
|
||||
)
|
||||
return OutBase()
|
||||
|
||||
@@ -829,6 +829,26 @@ class AppConfig(GlobalConfig):
|
||||
await script_config.UserData.setOrder([uuid.UUID(_) for _ in index_list])
|
||||
await self.ScriptConfig.save()
|
||||
|
||||
async def set_infrastructure(
|
||||
self, script_id: str, user_id: str, jsonFile: str
|
||||
) -> None:
|
||||
|
||||
logger.info(f"{script_id} - {user_id} 设置基建配置:{jsonFile}")
|
||||
|
||||
json_path = Path(jsonFile)
|
||||
|
||||
if not json_path.exists():
|
||||
raise FileNotFoundError(f"File not found: {json_path}")
|
||||
|
||||
(Path.cwd() / f"data/{script_id}/{user_id}/Infrastructure").mkdir(
|
||||
parents=True, exist_ok=True
|
||||
)
|
||||
shutil.copy(
|
||||
json_path,
|
||||
Path.cwd()
|
||||
/ f"data/{script_id}/{user_id}/Infrastructure/infrastructure.json",
|
||||
)
|
||||
|
||||
async def add_plan(
|
||||
self, script: Literal["MaaPlan"]
|
||||
) -> tuple[uuid.UUID, ConfigBase]:
|
||||
|
||||
@@ -230,11 +230,13 @@ class _TaskManager:
|
||||
|
||||
logger.info(f"中止任务:{task_id}")
|
||||
|
||||
if task_id == "ALL":
|
||||
for task in self.task_dict.values():
|
||||
task.cancel()
|
||||
else:
|
||||
uid = uuid.UUID(task_id)
|
||||
|
||||
if uid not in self.task_dict:
|
||||
raise ValueError(f"The task {uid} is not running.")
|
||||
|
||||
self.task_dict[uid].cancel()
|
||||
|
||||
async def remove_task(
|
||||
|
||||
@@ -514,6 +514,11 @@ class UserReorderIn(UserInBase):
|
||||
indexList: List[str] = Field(..., description="用户ID列表,按新顺序排列")
|
||||
|
||||
|
||||
class UserSetIn(UserInBase):
|
||||
userId: str = Field(..., description="用户ID")
|
||||
jsonFile: str = Field(..., description="JSON文件路径, 用于导入自定义基建文件")
|
||||
|
||||
|
||||
class PlanCreateIn(BaseModel):
|
||||
type: Literal["MaaPlan"]
|
||||
|
||||
|
||||
3
main.py
3
main.py
@@ -55,7 +55,7 @@ def main():
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
|
||||
from app.core import Config, MainTimer
|
||||
from app.core import Config, MainTimer, TaskManager
|
||||
from app.services import System
|
||||
|
||||
await Config.init_config()
|
||||
@@ -67,6 +67,7 @@ def main():
|
||||
|
||||
yield
|
||||
|
||||
await TaskManager.stop_task("ALL")
|
||||
main_timer.cancel()
|
||||
try:
|
||||
await main_timer
|
||||
|
||||
BIN
res/icons/AUTO_MAS.ico
Normal file
BIN
res/icons/AUTO_MAS.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 216 KiB |
Reference in New Issue
Block a user