最新可用

This commit is contained in:
2025-09-04 22:59:27 +08:00
parent ec6dbfde90
commit 30bf7c9fcb
42 changed files with 746 additions and 1967 deletions

View File

@ -1,6 +1,6 @@
import json
from fastapi import APIRouter, Query, HTTPException
from fastapi import APIRouter, Query, HTTPException,Request
from mysql.connector import Error as MySQLError
from ds.db import db
@ -108,7 +108,7 @@ def update_online_status_by_ip(client_ip: str, online_status: int) -> bool:
# 原有接口保持不变
# ------------------------------
@router.post("/add", response_model=APIResponse, summary="创建设备信息")
async def create_device(device_data: DeviceCreateRequest):
async def create_device(device_data: DeviceCreateRequest, request: Request): # 注入Request对象
# 原有代码保持不变
conn = None
cursor = None
@ -125,11 +125,10 @@ async def create_device(device_data: DeviceCreateRequest):
return APIResponse(
code=200,
message=f"设备IP {device_data.ip} 已存在,返回已有设备信息",
data=DeviceResponse(**existing_device)
data=DeviceResponse(** existing_device)
)
from fastapi import Request
request = Request(scope={"type": "http"})
# 直接使用注入的request对象获取用户代理
user_agent = request.headers.get("User-Agent", "").lower()
if user_agent == "default":
@ -184,7 +183,6 @@ async def create_device(device_data: DeviceCreateRequest):
finally:
db.close_connection(conn, cursor)
@router.get("/", response_model=APIResponse, summary="获取设备列表(支持筛选分页)")
async def get_device_list(
page: int = Query(1, ge=1, description="页码默认第1页"),