最新可用
This commit is contained in:
@ -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页"),
|
||||
|
Reference in New Issue
Block a user