修复lsfx删除文件接口logIds解析异常
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
from fastapi import APIRouter, BackgroundTasks, UploadFile, File, Form, Query
|
||||
import json
|
||||
|
||||
from fastapi import APIRouter, BackgroundTasks, UploadFile, File, Form, HTTPException, Query
|
||||
from services.token_service import TokenService
|
||||
from services.file_service import FileService
|
||||
from services.statement_service import StatementService
|
||||
@@ -14,6 +16,32 @@ file_service = FileService()
|
||||
statement_service = StatementService()
|
||||
|
||||
|
||||
def _parse_log_ids(log_ids: str) -> List[int]:
|
||||
"""兼容逗号分隔和 JSON 数组两种 logIds 传参格式。"""
|
||||
raw_value = log_ids.strip()
|
||||
if not raw_value:
|
||||
raise HTTPException(status_code=422, detail="logIds 不能为空")
|
||||
|
||||
try:
|
||||
if raw_value.startswith("["):
|
||||
parsed = json.loads(raw_value)
|
||||
if not isinstance(parsed, list):
|
||||
raise ValueError
|
||||
values = parsed
|
||||
else:
|
||||
values = [item.strip() for item in raw_value.split(",") if item.strip()]
|
||||
|
||||
if not values:
|
||||
raise ValueError
|
||||
|
||||
return [int(item) for item in values]
|
||||
except (TypeError, ValueError, json.JSONDecodeError) as exc:
|
||||
raise HTTPException(
|
||||
status_code=422,
|
||||
detail="logIds 必须是逗号分隔的数字字符串或 JSON 数组"
|
||||
) from exc
|
||||
|
||||
|
||||
# ==================== 接口1:获取Token ====================
|
||||
@router.post("/account/common/getToken")
|
||||
async def get_token(
|
||||
@@ -144,15 +172,14 @@ async def get_upload_status(
|
||||
@router.post("/watson/api/project/batchDeleteUploadFile")
|
||||
async def delete_files(
|
||||
groupId: int = Form(..., description="项目id"),
|
||||
logIds: str = Form(..., description="文件id数组,逗号分隔,如: 10001,10002"),
|
||||
logIds: str = Form(..., description="文件id数组,支持 10001,10002 或 [10001,10002]"),
|
||||
userId: int = Form(..., description="用户柜员号"),
|
||||
):
|
||||
"""批量删除上传的文件
|
||||
|
||||
根据logIds列表删除对应的文件记录
|
||||
"""
|
||||
# 将逗号分隔的字符串转换为整数列表
|
||||
log_id_list = [int(id.strip()) for id in logIds.split(",")]
|
||||
log_id_list = _parse_log_ids(logIds)
|
||||
return file_service.delete_files(groupId, log_id_list, userId)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user