代码优化
This commit is contained in:
parent
445e208d82
commit
b005d3a903
7
main.py
7
main.py
|
|
@ -8,7 +8,7 @@ from typing import Dict, Any, Optional, List
|
|||
from fastapi import FastAPI, HTTPException, Depends, Header
|
||||
from public_function.auth import verify_tk_token
|
||||
from public_function.public_func import read_config, create_logger
|
||||
from model.model import GoodsInfo, DataReceive, AccountCreate, AccountUpdate, TokenItem, CrawlerItem, ResetTask
|
||||
from model.model import GoodsInfo, DataReceive, AccountStatus, AccountUpdate, TokenItem, CrawlerItem, ResetTask
|
||||
|
||||
app = FastAPI()
|
||||
app.middleware("http")(verify_tk_token)
|
||||
|
|
@ -90,7 +90,7 @@ async def obtain_account(app_name: str, region: str, account_manager: Any = Depe
|
|||
|
||||
|
||||
@app.post("/account_status", summary="获取账号状态")
|
||||
async def account_status(account_data: AccountCreate, account_manager: Any = Depends(get_account_manager)):
|
||||
async def account_status(account_data: AccountStatus, account_manager: Any = Depends(get_account_manager)):
|
||||
"""
|
||||
新增爬虫账号
|
||||
- **account_id**: 账号ID
|
||||
|
|
@ -123,7 +123,8 @@ async def update_account(account_data: AccountUpdate, account_manager: Any = Dep
|
|||
result = await account_manager.update_account_info(set_param=set_param, where_conditions=where_conditions, params=params)
|
||||
if result:
|
||||
return {"code": 200, "message": "账号状态修改成功", "data": result}
|
||||
raise HTTPException(status_code=404, detail="账号状态修改失败")
|
||||
else:
|
||||
return {"code": 401, "message": "数据库中状态与传入状态一样"}
|
||||
except Exception as e:
|
||||
print(f"新增账号失败: {e}")
|
||||
raise HTTPException(status_code=500, detail="账号失败,请重试,失败原因:{}".format(e))
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from typing import Optional, Dict, Any
|
|||
|
||||
|
||||
# 定义数据模型
|
||||
class AccountCreate(BaseModel):
|
||||
class AccountStatus(BaseModel):
|
||||
account_id: str = Field(..., description="账号ID")
|
||||
app_name: str = Field(..., description="应用名称")
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue