|
|
@@ -2,6 +2,7 @@
|
|
|
路径验证工具
|
|
|
"""
|
|
|
import re
|
|
|
+import os
|
|
|
from fastapi import HTTPException
|
|
|
|
|
|
|
|
|
@@ -55,7 +56,9 @@ def sanitize_filename(filename: str) -> str:
|
|
|
"""
|
|
|
if not filename:
|
|
|
raise HTTPException(status_code=400, detail="文件名不能为空")
|
|
|
-
|
|
|
+
|
|
|
+ filename = os.path.basename(filename)
|
|
|
+
|
|
|
# 移除路径分隔符
|
|
|
filename = filename.replace('/', '').replace('\\', '')
|
|
|
|