Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/api/v1/endpoints/article.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@

@router.post("/uploadToSelfFolder", response_model="dict")
async def upload_to_self_folder(folder_id: int = Query(...), article: UploadFile = File(...), db: AsyncSession = Depends(get_db)):
# 由前端保证上传的为 PDF
# 检查上传的必须为 PDF
head = await article.read(5) # 读取文件的前 5 个字节,用于魔数检测
if not head.startswith(b"%PDF-"):
raise HTTPException(status_code=405, detail="File uploaded must be a PDF.")
await article.seek(0) # 重置文件指针位置

# 用文件名(不带扩展名)作为 Article 名称
name = os.path.splitext(article.filename)[0]

Expand Down