|
|
@@ -16,6 +16,7 @@ from app.services.sample_service import SampleService
|
|
|
from app.services.jwt_token import verify_token
|
|
|
from app.schemas.base import ApiResponse
|
|
|
from app.base import get_mineru_manager
|
|
|
+from app.utils.auth_dependency import get_current_user_with_refresh
|
|
|
|
|
|
from app.services.task_service import task_service
|
|
|
|
|
|
@@ -29,13 +30,9 @@ security_optional = HTTPBearer(auto_error=False)
|
|
|
|
|
|
|
|
|
@router.get("/tasks")
|
|
|
-async def get_tasks(type: str, credentials: HTTPAuthorizationCredentials = Depends(security)):
|
|
|
+async def get_tasks(type: str, current_user: dict = Depends(get_current_user_with_refresh)):
|
|
|
"""获取任务项目列表 (聚合显示)"""
|
|
|
try:
|
|
|
- payload = verify_token(credentials.credentials)
|
|
|
- if not payload:
|
|
|
- return ApiResponse(code=401, message="无效的访问令牌").model_dump()
|
|
|
-
|
|
|
projects = await task_service.get_task_list(type)
|
|
|
return ApiResponse(code=0, message="成功", data=projects).model_dump()
|
|
|
except Exception as e:
|
|
|
@@ -44,13 +41,9 @@ async def get_tasks(type: str, credentials: HTTPAuthorizationCredentials = Depen
|
|
|
|
|
|
|
|
|
@router.get("/tasks/details")
|
|
|
-async def get_task_details(project_id: str, type: str, credentials: HTTPAuthorizationCredentials = Depends(security)):
|
|
|
+async def get_task_details(project_id: str, type: str, current_user: dict = Depends(get_current_user_with_refresh)):
|
|
|
"""获取项目下的文件详情"""
|
|
|
try:
|
|
|
- payload = verify_token(credentials.credentials)
|
|
|
- if not payload:
|
|
|
- return ApiResponse(code=401, message="无效的访问令牌").model_dump()
|
|
|
-
|
|
|
files = await task_service.get_project_details(project_id, type)
|
|
|
return ApiResponse(code=0, message="成功", data=files).model_dump()
|
|
|
except Exception as e:
|
|
|
@@ -61,15 +54,11 @@ async def get_task_details(project_id: str, type: str, credentials: HTTPAuthoriz
|
|
|
# --- 外部联动接口 API ---
|
|
|
|
|
|
@router.post("/external/projects/init", status_code=201)
|
|
|
-async def init_external_project(request: Request, credentials: HTTPAuthorizationCredentials = Depends(security)):
|
|
|
+async def init_external_project(request: Request, current_user: dict = Depends(get_current_user_with_refresh)):
|
|
|
"""项目初始化接口:由标注平台调用,同步数据"""
|
|
|
try:
|
|
|
- payload = verify_token(credentials.credentials)
|
|
|
- if not payload:
|
|
|
- return ApiResponse(code=401, message="无效的访问令牌").model_dump()
|
|
|
-
|
|
|
# 简单验证是否为管理员(根据业务需求调整)
|
|
|
- if not payload.get("is_superuser") and payload.get("role") != "admin":
|
|
|
+ if not current_user.get("is_superuser") and current_user.get("role") != "admin":
|
|
|
return ApiResponse(code=403, message="权限不足").model_dump()
|
|
|
|
|
|
data = await request.json()
|
|
|
@@ -87,14 +76,10 @@ async def init_external_project(request: Request, credentials: HTTPAuthorization
|
|
|
@router.get("/external/projects/progress")
|
|
|
async def get_external_project_progress(
|
|
|
project_id: Optional[str] = None,
|
|
|
- credentials: HTTPAuthorizationCredentials = Depends(security)
|
|
|
+ current_user: dict = Depends(get_current_user_with_refresh)
|
|
|
):
|
|
|
"""查询项目进度"""
|
|
|
try:
|
|
|
- payload = verify_token(credentials.credentials)
|
|
|
- if not payload:
|
|
|
- return ApiResponse(code=401, message="无效的访问令牌").model_dump()
|
|
|
-
|
|
|
if not project_id:
|
|
|
return ApiResponse(code=400, message="缺少项目ID").model_dump()
|
|
|
|
|
|
@@ -112,15 +97,10 @@ async def get_external_project_progress(
|
|
|
async def export_external_project(
|
|
|
req: ExportRequest,
|
|
|
project_id: Optional[str] = None,
|
|
|
- credentials: HTTPAuthorizationCredentials = Depends(security)
|
|
|
+ current_user: dict = Depends(get_current_user_with_refresh)
|
|
|
):
|
|
|
"""导出项目已完成的标注数据"""
|
|
|
try:
|
|
|
- logger.debug(f"收到导出请求: project_id={project_id}, req={req.model_dump()}, has_credentials={bool(credentials.credentials)}")
|
|
|
- payload = verify_token(credentials.credentials)
|
|
|
- if not payload:
|
|
|
- logger.warning(f"导出请求 Token 验证失败: {credentials.credentials[:10]}...")
|
|
|
- return ApiResponse(code=401, message="无效的访问令牌").model_dump()
|
|
|
|
|
|
# 优先从路径获取 project_id,否则从 body 获取
|
|
|
actual_project_id = project_id or req.project_id
|
|
|
@@ -146,12 +126,9 @@ async def export_external_project(
|
|
|
return ApiResponse(code=500, message=str(e)).model_dump()
|
|
|
|
|
|
@router.get("/external/download-proxy")
|
|
|
-async def download_proxy(url: str, filename: str, credentials: HTTPAuthorizationCredentials = Depends(security)):
|
|
|
+async def download_proxy(url: str, filename: str, current_user: dict = Depends(get_current_user_with_refresh)):
|
|
|
"""后端中转下载外部平台文件,解决跨域和 Token 携带问题"""
|
|
|
try:
|
|
|
- payload = verify_token(credentials.credentials)
|
|
|
- if not payload:
|
|
|
- raise HTTPException(status_code=401, detail="无效的访问令牌")
|
|
|
|
|
|
# 确保 URL 是完整的
|
|
|
if not url.startswith('http'):
|
|
|
@@ -166,7 +143,7 @@ async def download_proxy(url: str, filename: str, credentials: HTTPAuthorization
|
|
|
admin_token = config_handler.get("external_api", "admin_token", "")
|
|
|
if not admin_token:
|
|
|
# 如果配置中没有,则尝试使用当前用户的 Token(兜底)
|
|
|
- admin_token = credentials.credentials
|
|
|
+ admin_token = current_user.credentials
|
|
|
|
|
|
client = httpx.AsyncClient(timeout=60.0, follow_redirects=True)
|
|
|
headers = {
|
|
|
@@ -204,13 +181,9 @@ async def download_proxy(url: str, filename: str, credentials: HTTPAuthorization
|
|
|
return ApiResponse(code=500, message=str(e)).model_dump()
|
|
|
|
|
|
@router.post("/documents/upload-url")
|
|
|
-async def get_upload_url(req: UploadUrlRequest, credentials: HTTPAuthorizationCredentials = Depends(security)):
|
|
|
+async def get_upload_url(req: UploadUrlRequest, credentials: dict = Depends(get_current_user_with_refresh)):
|
|
|
"""获取 MinIO 预签名上传 URL"""
|
|
|
try:
|
|
|
- payload = verify_token(credentials.credentials)
|
|
|
- if not payload:
|
|
|
- return ApiResponse(code=401, message="无效的访问令牌").model_dump()
|
|
|
-
|
|
|
sample_service = SampleService()
|
|
|
success, message, data = await sample_service.get_upload_url(req.filename, req.content_type, prefix=req.prefix)
|
|
|
|
|
|
@@ -226,22 +199,19 @@ async def get_upload_url(req: UploadUrlRequest, credentials: HTTPAuthorizationCr
|
|
|
async def proxy_view(url: str, token: Optional[str] = None, credentials: Optional[HTTPAuthorizationCredentials] = Depends(security_optional)):
|
|
|
"""抓取外部文档内容并返回,支持 HTML 和 PDF 等二进制文件。支持从 Header 或 Query 参数获取 Token。"""
|
|
|
try:
|
|
|
+ logger.info(f"token={token},credentials={credentials}")
|
|
|
# 确保 URL 已解码
|
|
|
url = urllib.parse.unquote(url)
|
|
|
-
|
|
|
- # 优先从 Header 获取,如果没有则从参数获取
|
|
|
+ # 优先从 Header 获取,如果没有则从参数获取
|
|
|
actual_token = None
|
|
|
if credentials:
|
|
|
actual_token = credentials.credentials
|
|
|
elif token:
|
|
|
actual_token = token
|
|
|
-
|
|
|
+
|
|
|
if not actual_token:
|
|
|
return ApiResponse(code=401, message="未提供认证令牌", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
- payload = verify_token(actual_token)
|
|
|
- if not payload or not payload.get("is_superuser"):
|
|
|
- return ApiResponse(code=403, message="权限不足", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
# 增加超时时间,支持大文件下载
|
|
|
async with httpx.AsyncClient(timeout=30.0, follow_redirects=True) as client:
|
|
|
@@ -348,9 +318,6 @@ async def download_document(url: str, filename: Optional[str] = None, token: Opt
|
|
|
if not actual_token:
|
|
|
return ApiResponse(code=401, message="未提供认证令牌", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
- payload = verify_token(actual_token)
|
|
|
- if not payload or not payload.get("is_superuser"):
|
|
|
- return ApiResponse(code=403, message="权限不足", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
# 增加超时时间,支持大文件下载
|
|
|
async with httpx.AsyncClient(timeout=60.0, follow_redirects=True) as client:
|
|
|
@@ -379,14 +346,11 @@ async def download_document(url: str, filename: Optional[str] = None, token: Opt
|
|
|
return ApiResponse(code=500, message=f"下载失败: {str(e)} (URL: {url})", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
@router.post("/documents/batch-enter")
|
|
|
-async def batch_enter_knowledge_base(req: BatchEnterRequest, credentials: HTTPAuthorizationCredentials = Depends(security)):
|
|
|
+async def batch_enter_knowledge_base(req: BatchEnterRequest, current_user: dict = Depends(get_current_user_with_refresh)):
|
|
|
"""批量将文档加入知识库"""
|
|
|
try:
|
|
|
- payload = verify_token(credentials.credentials)
|
|
|
- if not payload or not payload.get("is_superuser"):
|
|
|
- return ApiResponse(code=403, message="权限不足", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
- username = payload.get("sub")
|
|
|
+ username = current_user.get("sub")
|
|
|
if not username:
|
|
|
return ApiResponse(code=401, message="令牌中缺少用户信息", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
@@ -408,12 +372,9 @@ async def batch_enter_knowledge_base(req: BatchEnterRequest, credentials: HTTPAu
|
|
|
return ApiResponse(code=500, message=f"批量操作失败: {str(e)}", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
@router.post("/documents/batch-delete")
|
|
|
-async def batch_delete_documents(req: BatchDeleteRequest, credentials: HTTPAuthorizationCredentials = Depends(security)):
|
|
|
+async def batch_delete_documents(req: BatchDeleteRequest, current_user: dict = Depends(get_current_user_with_refresh)):
|
|
|
"""批量删除文档"""
|
|
|
try:
|
|
|
- payload = verify_token(credentials.credentials)
|
|
|
- if not payload or not payload.get("is_superuser"):
|
|
|
- return ApiResponse(code=403, message="权限不足", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
sample_service = SampleService()
|
|
|
affected_rows, message = await sample_service.batch_delete_documents(req.ids)
|
|
|
@@ -435,18 +396,15 @@ class BatchAddTaskRequest(BaseModel):
|
|
|
tags: Optional[List[str]] = None
|
|
|
|
|
|
@router.post("/documents/batch-add-to-task")
|
|
|
-async def batch_add_to_task(req: BatchAddTaskRequest, credentials: HTTPAuthorizationCredentials = Depends(security)):
|
|
|
+async def batch_add_to_task(req: BatchAddTaskRequest, current_user: dict = Depends(get_current_user_with_refresh)):
|
|
|
"""批量加入任务中心 (设置 whether_to_task = 1)"""
|
|
|
try:
|
|
|
- payload = verify_token(credentials.credentials)
|
|
|
- if not payload or not payload.get("is_superuser"):
|
|
|
- return ApiResponse(code=403, message="权限不足", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
- user_id = payload.get("sub")
|
|
|
+ user_id = current_user.get("sub")
|
|
|
if not user_id:
|
|
|
return ApiResponse(code=401, message="令牌中缺少用户信息", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
- username = payload.get("username", user_id)
|
|
|
+ username = current_user.get("username", user_id)
|
|
|
|
|
|
sample_service = SampleService()
|
|
|
success, message = await sample_service.batch_add_to_task(req.doc_ids, username, req.project_name, task_tags=req.tags)
|
|
|
@@ -461,12 +419,9 @@ async def batch_add_to_task(req: BatchAddTaskRequest, credentials: HTTPAuthoriza
|
|
|
return ApiResponse(code=500, message=f"批量加入任务失败: {str(e)}", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
@router.post("/documents/convert")
|
|
|
-async def convert_document(req: ConvertRequest, background_tasks: BackgroundTasks, credentials: HTTPAuthorizationCredentials = Depends(security)):
|
|
|
+async def convert_document(req: ConvertRequest, background_tasks: BackgroundTasks, current_user: dict = Depends(get_current_user_with_refresh)):
|
|
|
"""启动文档转换 (使用 MinerUManager 在后台执行)"""
|
|
|
try:
|
|
|
- payload = verify_token(credentials.credentials)
|
|
|
- if not payload or not payload.get("is_superuser"):
|
|
|
- return ApiResponse(code=403, message="权限不足", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
doc_id = str(req.id)
|
|
|
sample_service = SampleService()
|
|
|
@@ -508,14 +463,11 @@ async def convert_document(req: ConvertRequest, background_tasks: BackgroundTask
|
|
|
return ApiResponse(code=500, message=f"启动转换失败: {str(e)}", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
@router.post("/documents/add")
|
|
|
-async def add_document(doc: DocumentAdd, credentials: HTTPAuthorizationCredentials = Depends(security)):
|
|
|
+async def add_document(doc: DocumentAdd, current_user: dict = Depends(get_current_user_with_refresh)):
|
|
|
"""添加新文档 (同步主表和子表)"""
|
|
|
try:
|
|
|
- payload = verify_token(credentials.credentials)
|
|
|
- if not payload:
|
|
|
- return ApiResponse(code=401, message="无效的访问令牌", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
- user_id = payload.get("sub")
|
|
|
+ user_id = current_user.get("sub")
|
|
|
if not user_id:
|
|
|
return ApiResponse(code=401, message="令牌中缺少用户信息", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
@@ -535,12 +487,9 @@ async def add_document(doc: DocumentAdd, credentials: HTTPAuthorizationCredentia
|
|
|
return ApiResponse(code=500, message=str(e), timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
@router.get("/documents/detail/{doc_id}")
|
|
|
-async def get_document_detail(doc_id: str, credentials: HTTPAuthorizationCredentials = Depends(security)):
|
|
|
+async def get_document_detail(doc_id: str, current_user: dict = Depends(get_current_user_with_refresh)):
|
|
|
"""获取文档详情 (关联查询子表)"""
|
|
|
try:
|
|
|
- payload = verify_token(credentials.credentials)
|
|
|
- if not payload:
|
|
|
- return ApiResponse(code=401, message="无效的访问令牌", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
sample_service = SampleService()
|
|
|
doc = await sample_service.get_document_detail(doc_id)
|
|
|
@@ -566,13 +515,10 @@ async def get_document_list(
|
|
|
level_4_classification: Optional[str] = None,
|
|
|
page: int = 1,
|
|
|
size: int = 50,
|
|
|
- credentials: HTTPAuthorizationCredentials = Depends(security)
|
|
|
+ current_user: dict = Depends(get_current_user_with_refresh)
|
|
|
):
|
|
|
"""获取文档列表 (从主表查询)"""
|
|
|
try:
|
|
|
- payload = verify_token(credentials.credentials)
|
|
|
- if not payload:
|
|
|
- return ApiResponse(code=401, message="无效的访问令牌", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
sample_service = SampleService()
|
|
|
items, total, all_total, total_entered = await sample_service.get_document_list(
|
|
|
@@ -606,12 +552,9 @@ async def get_document_list(
|
|
|
return ApiResponse(code=500, message=str(e), timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
@router.post("/documents/edit")
|
|
|
-async def edit_document(doc: DocumentAdd, credentials: HTTPAuthorizationCredentials = Depends(security)):
|
|
|
+async def edit_document(doc: DocumentAdd, current_user: dict = Depends(get_current_user_with_refresh)):
|
|
|
"""编辑文档 (同步主表和子表)"""
|
|
|
try:
|
|
|
- payload = verify_token(credentials.credentials)
|
|
|
- if not payload:
|
|
|
- return ApiResponse(code=401, message="无效的访问令牌", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
if not doc.id:
|
|
|
return ApiResponse(code=400, message="缺少ID参数", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
@@ -620,7 +563,7 @@ async def edit_document(doc: DocumentAdd, credentials: HTTPAuthorizationCredenti
|
|
|
sample_service = SampleService()
|
|
|
|
|
|
# 获取更新人ID
|
|
|
- updater_id = payload.get("sub", "admin")
|
|
|
+ updater_id = current_user.get("sub", "admin")
|
|
|
|
|
|
# 将 DocumentAdd 对象转换为字典,包含所有字段
|
|
|
doc_data = doc.model_dump()
|
|
|
@@ -636,15 +579,14 @@ async def edit_document(doc: DocumentAdd, credentials: HTTPAuthorizationCredenti
|
|
|
return ApiResponse(code=500, message=str(e), timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
@router.post("/documents/enter")
|
|
|
-async def enter_document(data: dict, credentials: HTTPAuthorizationCredentials = Depends(security)):
|
|
|
+async def enter_document(data: dict, current_user: dict = Depends(get_current_user_with_refresh)):
|
|
|
"""文档入库"""
|
|
|
try:
|
|
|
doc_id = data.get("id")
|
|
|
if not doc_id:
|
|
|
return ApiResponse(code=400, message="缺少ID", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
- payload = verify_token(credentials.credentials)
|
|
|
- username = payload.get("sub", "admin") if payload else "admin"
|
|
|
+ username = current_user.get("sub", "admin") if payload else "admin"
|
|
|
|
|
|
# 调用 service 层
|
|
|
sample_service = SampleService()
|
|
|
@@ -679,13 +621,10 @@ async def get_basic_info_list(
|
|
|
level_2_classification: Optional[str] = None,
|
|
|
level_3_classification: Optional[str] = None,
|
|
|
level_4_classification: Optional[str] = None,
|
|
|
- credentials: HTTPAuthorizationCredentials = Depends(security)
|
|
|
+ current_user: dict = Depends(get_current_user_with_refresh)
|
|
|
):
|
|
|
"""获取基本信息列表 (支持多条件检索)"""
|
|
|
try:
|
|
|
- payload = verify_token(credentials.credentials)
|
|
|
- if not payload:
|
|
|
- return ApiResponse(code=401, message="无效的访问令牌", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
sample_service = SampleService()
|
|
|
|
|
|
@@ -738,14 +677,11 @@ async def get_basic_info_list(
|
|
|
return ApiResponse(code=500, message=f"服务器内部错误: {str(e)}", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
@router.post("/basic-info/add")
|
|
|
-async def add_basic_info(type: str, data: dict, credentials: HTTPAuthorizationCredentials = Depends(security)):
|
|
|
+async def add_basic_info(type: str, data: dict, current_user: dict = Depends(get_current_user_with_refresh)):
|
|
|
"""新增基本信息"""
|
|
|
try:
|
|
|
- payload = verify_token(credentials.credentials)
|
|
|
- if not payload:
|
|
|
- return ApiResponse(code=401, message="无效的访问令牌", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
- user_id = payload.get("sub")
|
|
|
+ user_id = current_user.get("sub")
|
|
|
if not user_id:
|
|
|
return ApiResponse(code=401, message="令牌中缺少用户信息", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
@@ -761,14 +697,11 @@ async def add_basic_info(type: str, data: dict, credentials: HTTPAuthorizationCr
|
|
|
return ApiResponse(code=500, message=str(e), timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
@router.post("/basic-info/edit")
|
|
|
-async def edit_basic_info(type: str, id: str, data: dict, credentials: HTTPAuthorizationCredentials = Depends(security)):
|
|
|
+async def edit_basic_info(type: str, id: str, data: dict, current_user: dict = Depends(get_current_user_with_refresh)):
|
|
|
"""编辑基本信息"""
|
|
|
try:
|
|
|
- payload = verify_token(credentials.credentials)
|
|
|
- if not payload:
|
|
|
- return ApiResponse(code=401, message="无效的访问令牌", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
- user_id = payload.get("sub")
|
|
|
+ user_id = current_user.get("sub")
|
|
|
if not user_id:
|
|
|
return ApiResponse(code=401, message="令牌中缺少用户信息", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
@@ -784,12 +717,9 @@ async def edit_basic_info(type: str, id: str, data: dict, credentials: HTTPAutho
|
|
|
return ApiResponse(code=500, message=str(e), timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
@router.post("/basic-info/delete")
|
|
|
-async def delete_basic_info(type: str, id: str, credentials: HTTPAuthorizationCredentials = Depends(security)):
|
|
|
+async def delete_basic_info(type: str, id: str, current_user: dict = Depends(get_current_user_with_refresh)):
|
|
|
"""删除基本信息"""
|
|
|
try:
|
|
|
- payload = verify_token(credentials.credentials)
|
|
|
- if not payload:
|
|
|
- return ApiResponse(code=401, message="无效的访问令牌", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
sample_service = SampleService()
|
|
|
success, message = await sample_service.delete_basic_info(type, id)
|
|
|
@@ -803,12 +733,9 @@ async def delete_basic_info(type: str, id: str, credentials: HTTPAuthorizationCr
|
|
|
return ApiResponse(code=500, message=str(e), timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
@router.get("/documents/categories/primary")
|
|
|
-async def get_primary_categories(credentials: HTTPAuthorizationCredentials = Depends(security)):
|
|
|
+async def get_primary_categories(current_user: dict = Depends(get_current_user_with_refresh)):
|
|
|
"""获取所有一级分类(仅保留指定的分类)"""
|
|
|
try:
|
|
|
- payload = verify_token(credentials.credentials)
|
|
|
- if not payload or not payload.get("is_superuser"):
|
|
|
- return ApiResponse(code=403, message="权限不足", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
# 仅保留用户要求的分类
|
|
|
default_categories = ["办公制度", "行业标准", "法律法规", "施工方案", "施工图片"]
|
|
|
@@ -818,12 +745,9 @@ async def get_primary_categories(credentials: HTTPAuthorizationCredentials = Dep
|
|
|
return ApiResponse(code=500, message=str(e), timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
@router.get("/documents/categories/secondary")
|
|
|
-async def get_secondary_categories(primaryId: str, credentials: HTTPAuthorizationCredentials = Depends(security)):
|
|
|
+async def get_secondary_categories(primaryId: str, current_user: dict = Depends(get_current_user_with_refresh)):
|
|
|
"""根据一级分类获取二级分类(仅保留指定的分类)"""
|
|
|
try:
|
|
|
- payload = verify_token(credentials.credentials)
|
|
|
- if not payload or not payload.get("is_superuser"):
|
|
|
- return ApiResponse(code=403, message="权限不足", timestamp=datetime.now(timezone.utc).isoformat()).model_dump()
|
|
|
|
|
|
# 针对“办公制度”的预设二级分类,其他分类暂时没有二级分类
|
|
|
categories = []
|
|
|
@@ -842,7 +766,7 @@ async def search_documents(
|
|
|
table_type: Optional[str] = "standard",
|
|
|
page: int = 1,
|
|
|
size: int = 50,
|
|
|
- credentials: HTTPAuthorizationCredentials = Depends(security)
|
|
|
+ current_user: dict = Depends(get_current_user_with_refresh)
|
|
|
):
|
|
|
"""关键词搜索文档,统一调用 get_document_list 以支持组合过滤"""
|
|
|
return await get_document_list(
|