feat: 添加环境信息

This commit is contained in:
DLmaster361
2025-08-06 16:48:43 +08:00
parent b5c118eee5
commit 8cbd542a75
10 changed files with 134 additions and 327 deletions

57
app/api/dispatch.py Normal file
View File

@@ -0,0 +1,57 @@
# AUTO_MAA:A MAA Multi Account Management and Automation Tool
# Copyright © 2024-2025 DLmaster361
# Copyright © 2025 MoeSnowyFox
# This file is part of AUTO_MAA.
# AUTO_MAA is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published
# by the Free Software Foundation, either version 3 of the License,
# or (at your option) any later version.
# AUTO_MAA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
# the GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with AUTO_MAA. If not, see <https://www.gnu.org/licenses/>.
# Contact: DLmaster_361@163.com
from fastapi import APIRouter, Body
from core import Config
from models.schema import *
router = APIRouter(prefix="/api/dispatch", tags=["任务调度"])
@router.post("/add", summary="添加任务", response_model=OutBase, status_code=200)
async def add_plan(plan: DispatchIn = Body(...)) -> OutBase:
uid, config = await Config.add_plan(plan.type)
return OutBase(code=200, status="success", message="任务添加成功")
@router.post("/stop", summary="中止任务", response_model=OutBase, status_code=200)
async def stop_plan(plan: DispatchIn = Body(...)) -> OutBase:
try:
await Config.del_plan(plan.taskId)
except Exception as e:
return OutBase(code=500, status="error", message=str(e))
return OutBase()
@router.post(
"/order", summary="重新排序计划表", response_model=OutBase, status_code=200
)
async def reorder_plan(plan: PlanReorderIn = Body(...)) -> OutBase:
try:
await Config.reorder_plan(plan.indexList)
except Exception as e:
return OutBase(code=500, status="error", message=str(e))
return OutBase()

View File

@@ -19,11 +19,12 @@
# Contact: DLmaster_361@163.com
import uuid
from datetime import datetime
from packaging import version
from typing import Dict, Union
from .config import Config
from .config import Config, MaaConfig, GeneralConfig
from utils import get_logger
from task import *
@@ -254,17 +255,36 @@ class _TaskManager:
self.task_dict: Dict[str, Task] = {}
def add_task(
self, mode: str, name: str, info: Dict[str, Dict[str, Union[str, int, bool]]]
):
def add_task(self, mode: str, uid: str):
"""
添加任务
:param mode: 任务模式
:param name: 任务名称
:param info: 任务信息
:param uid: 任务UID
"""
actual_id = uuid.UUID(uid)
if mode == "设置脚本":
if actual_id in Config.ScriptConfig:
task_id = actual_id
else:
for script_id, script in Config.ScriptConfig.items():
if (
isinstance(script, (MaaConfig | GeneralConfig))
and actual_id in script.UserData
):
task_id = script_id
break
else:
raise ValueError(
f"The task corresponding to UID {uid} could not be found."
)
elif actual_id in Config.QueueConfig or actual_id in Config.ScriptConfig:
task_id = actual_id
else:
raise ValueError(f"The task corresponding to UID {uid} could not be found.")
if name in Config.running_list or name in self.task_dict:
logger.warning(f"任务已存在:{name}")
@@ -383,67 +403,5 @@ class _TaskManager:
if Config.args.mode == "cli" and Config.power_sign == "NoAction":
Config.set_power_sign("KillSelf")
def check_maa_version(self, v: str) -> None:
"""
检查MAA版本如果版本过低则推送通知
:param v: 当前MAA版本
"""
logger.info(f"检查MAA版本{v}", module="业务调度")
network = Network.add_task(
mode="get",
url="https://mirrorchyan.com/api/resources/MAA/latest?user_agent=AutoMaaGui&os=win&arch=x64&channel=stable",
)
network.loop.exec()
network_result = Network.get_result(network)
if network_result["status_code"] == 200:
maa_info = network_result["response_json"]
else:
logger.warning(
f"获取MAA版本信息时出错{network_result['error_message']}",
module="业务调度",
)
MainInfoBar.push_info_bar(
"warning",
"获取MAA版本信息时出错",
f"网络错误:{network_result['status_code']}",
5000,
)
return None
if version.parse(maa_info["data"]["version_name"]) > version.parse(v):
logger.info(
f"检测到MAA版本过低{v},最新版本:{maa_info['data']['version_name']}",
module="业务调度",
)
MainInfoBar.push_info_bar(
"info",
"MAA版本过低",
f"当前版本:{v},最新稳定版:{maa_info['data']['version_name']}",
-1,
)
logger.success(
f"MAA版本检查完成{v},最新版本:{maa_info['data']['version_name']}",
module="业务调度",
)
def push_dialog(self, name: str, title: str, content: str):
"""
推送来自任务线程的对话框
:param name: 任务名称
:param title: 对话框标题
:param content: 对话框内容
"""
choice = MessageBox(title, content, Config.main_window)
choice.yesButton.setText("")
choice.cancelButton.setText("")
self.task_dict[name].question_response.emit(bool(choice.exec()))
TaskManager = _TaskManager()

View File

@@ -185,6 +185,19 @@ class QueueItemReorderIn(QueueSetInBase):
indexList: List[str] = Field(..., description="队列项ID列表按新顺序排列")
class DispatchIn(BaseModel):
taskId: str = Field(
...,
description="目标任务ID设置类任务可选对应脚本ID或用户ID代理类任务可选对应队列ID或脚本ID",
)
class DispatchCreateIn(DispatchIn):
mode: Literal["自动代理", "人工排查", "设置脚本"] = Field(
..., description="任务模式"
)
class SettingGetOut(OutBase):
data: Dict[str, Dict[str, Any]] = Field(..., description="全局设置数据")