添加账号删除功能

This commit is contained in:
liujianjiang 2025-11-26 18:06:19 +08:00
parent 7be55dc059
commit 231526c1ff
3 changed files with 26 additions and 6 deletions

View File

@ -18,12 +18,9 @@ class DealAccount:
return True
return False
async def delete_account(self, params: List[str]):
async def delete_account(self, params: Dict[str, Any]):
"""删除账户"""
if len(params) == 1:
condition = "account_id={}".format(params[0])
else:
condition = f"account_id in ({','.join(params)})"
condition = "account_id='{}' and app_name='{}'".format(params["account_id"], params["app_name"])
await self.db_pool.initialize()
result = await self.db_pool.delete(table="crawler_account_record_info", where_conditions=condition)
if result:

20
main.py
View File

@ -8,7 +8,7 @@ from typing import Dict, Any, Optional, List
from fastapi import FastAPI, HTTPException, Depends
from public_function.public_func import read_config
from model.model import AccountCreate, AccountUpdate, CrawlerTask
from model.model import AccountCreate, AccountUpdate, CrawlerTask, AccountDelete
app = FastAPI()
@ -87,6 +87,24 @@ async def add_account(account_data: AccountCreate, account_manager: Any = Depend
raise HTTPException(status_code=500, detail="新增账号失败,失败原因:{}".format(e))
@app.post("/delete_account", summary="新增账号")
async def delete_account(account_data: AccountDelete, account_manager: Any = Depends(get_account_manager)):
"""
删除爬虫账号
- **account_id**: 账号ID
- **password**: 密码
- **app_name**: 应用名称
"""
try:
print(account_data.dict())
# 这里应该调用实际的添加账号方法
result = await account_manager.delete_account(account_data.dict())
return {"code": 200, "message": "删除账号成功", "data": result}
except Exception as e:
print(f"新增账号失败: {e}")
raise HTTPException(status_code=500, detail="删除账号失败,请重试,失败原因:{}".format(e))
@app.post("/receive_data")
async def receive_data(params: Dict[str, Any]):
"""数据接收接口"""

View File

@ -15,6 +15,11 @@ class AccountUpdate(BaseModel):
status: int = Field(..., ge=1, le=2, description="状态1-空闲2-使用中")
class AccountDelete(BaseModel):
account_id: str = Field(..., min_length=1, max_length=128, description="账号ID")
app_name: str = Field(..., min_length=1, max_length=128, description="应用名称")
class CrawlerTask(BaseModel):
country: str = Field(..., min_length=1, max_length=128, description="账号所在国家")
app_name: str = Field(..., min_length=1, max_length=128, description="应用名称")