diff --git a/app/api/info.py b/app/api/info.py index 00378eb..a2fa90a 100644 --- a/app/api/info.py +++ b/app/api/info.py @@ -40,6 +40,21 @@ async def get_stage_info() -> InfoOut: return InfoOut(data=data) +@router.post( + "/combox/script", + summary="获取脚本下拉框信息", + response_model=ComboBoxOut, + status_code=200, +) +async def get_script_combox() -> ComboBoxOut: + + try: + data: List[ComboBoxItem] = await Config.get_script_combox() + except Exception as e: + return ComboBoxOut(code=500, status="error", message=str(e), data=[]) + return ComboBoxOut(data=data) + + @router.post("/notice", summary="获取通知信息", response_model=InfoOut, status_code=200) async def get_notice_info() -> InfoOut: diff --git a/app/core/config.py b/app/core/config.py index 9fe85d6..5c1b7a9 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -627,6 +627,7 @@ class GeneralConfig(ConfigBase): CLASS_BOOK = {"MAA": MaaConfig, "MaaPlan": MaaPlanConfig, "General": GeneralConfig} +TYPE_BOOK = {"MaaConfig": "MAA", "GeneralConfig": "通用"} class AppConfig(GlobalConfig): @@ -1262,6 +1263,22 @@ class AppConfig(GlobalConfig): return True, {"ALL": results} + async def get_script_combox(self): + """获取脚本下拉框信息""" + + logger.info("Getting script combo box information...") + data = [] + for uid, script in self.ScriptConfig.items(): + data.append( + { + "label": f"{TYPE_BOOK[script.__class__.__name__]} - {script.get('Info', 'Name')}", + "value": str(uid), + } + ) + logger.success("Script combo box information retrieved successfully.") + + return data + async def get_server_info(self, type: str) -> Dict[str, Any]: """获取公告信息""" diff --git a/app/models/schema.py b/app/models/schema.py index e5153fa..bd89ca5 100644 --- a/app/models/schema.py +++ b/app/models/schema.py @@ -34,6 +34,15 @@ class InfoOut(OutBase): data: Dict[str, Any] = Field(..., description="收到的服务器数据") +class ComboBoxItem(BaseModel): + label: str = Field(..., description="展示值") + value: str = Field(..., description="实际值") + + +class ComboBoxOut(OutBase): + data: List[ComboBoxItem] = Field(..., description="下拉框选项") + + class GlobalConfig_Function(BaseModel): HistoryRetentionTime: Optional[Literal[7, 15, 30, 60, 90, 180, 365, 0]] = Field( None, description="历史记录保留时间, 0表示永久保存"