feat: 添加电源接口,适配小功能函数

This commit is contained in:
DLmaster361
2025-08-17 10:53:00 +08:00
parent 1fdac22bea
commit 8e2c6bb642
7 changed files with 94 additions and 84 deletions

View File

@@ -25,6 +25,7 @@ import asyncio
from fastapi import APIRouter, WebSocket, WebSocketDisconnect, Body, Path
from app.core import TaskManager, Broadcast
from app.services import System
from app.models.schema import *
router = APIRouter(prefix="/api/dispatch", tags=["任务调度"])
@@ -59,6 +60,18 @@ async def stop_task(task: DispatchIn = Body(...)) -> OutBase:
return OutBase()
@router.post("/power", summary="电源操作", response_model=OutBase, status_code=200)
async def power_task(task: PowerIn = Body(...)) -> OutBase:
try:
await System.set_power(task.signal)
except Exception as e:
return OutBase(
code=500, status="error", message=f"{type(e).__name__}: {str(e)}"
)
return OutBase()
@router.websocket("/ws/{websocketId}")
async def websocket_endpoint(
websocket: WebSocket,

View File

@@ -20,9 +20,13 @@
# Contact: DLmaster_361@163.com
import os
from pathlib import Path
import shutil
from fastapi import APIRouter, Body
from app.core import Config
from app.services import System
from app.models.schema import *
router = APIRouter(prefix="/api/setting", tags=["全局设置"])
@@ -49,7 +53,28 @@ async def update_script(script: SettingUpdateIn = Body(...)) -> OutBase:
"""更新配置"""
try:
await Config.update_setting(script.data.model_dump(exclude_unset=True))
data = script.data.model_dump(exclude_unset=True)
await Config.update_setting(data)
if data.get("Start", {}).get("IfSelfStart", None) is not None:
await System.set_SelfStart()
if data.get("Function", None) is not None:
function = data["Function"]
if function.get("IfAllowSleep", None) is not None:
await System.set_Sleep()
if function.get("IfSkipMumuSplashAds", None) is not None:
MuMu_splash_ads_path = (
Path(os.getenv("APPDATA") or "")
/ "Netease/MuMuPlayer-12.0/data/startupImage"
)
if Config.get("Function", "IfSkipMumuSplashAds"):
if MuMu_splash_ads_path.exists() and MuMu_splash_ads_path.is_dir():
shutil.rmtree(MuMu_splash_ads_path)
MuMu_splash_ads_path.touch()
else:
if MuMu_splash_ads_path.exists() and MuMu_splash_ads_path.is_file():
MuMu_splash_ads_path.unlink()
except Exception as e:
return OutBase(
code=500, status="error", message=f"{type(e).__name__}: {str(e)}"