Initial commit: AI Interview System
This commit is contained in:
35
backend/app/routers/files.py
Normal file
35
backend/app/routers/files.py
Normal file
@@ -0,0 +1,35 @@
|
||||
"""
|
||||
文件服务接口 - 提供文件下载
|
||||
"""
|
||||
import os
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi.responses import FileResponse
|
||||
from loguru import logger
|
||||
|
||||
from app.config import settings
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/files/{file_id}")
|
||||
async def download_file(file_id: str):
|
||||
"""
|
||||
下载文件(供 Coze 工作流访问)
|
||||
|
||||
文件路径: uploads/{file_id}.pdf
|
||||
"""
|
||||
# 构建文件路径
|
||||
file_path = os.path.join(settings.UPLOAD_DIR, f"{file_id}.pdf")
|
||||
|
||||
# 检查文件是否存在
|
||||
if not os.path.exists(file_path):
|
||||
logger.error(f"File not found: {file_path}")
|
||||
raise HTTPException(status_code=404, detail="文件不存在")
|
||||
|
||||
logger.info(f"Serving file: {file_path}")
|
||||
|
||||
return FileResponse(
|
||||
path=file_path,
|
||||
filename=f"{file_id}.pdf",
|
||||
media_type="application/pdf"
|
||||
)
|
||||
Reference in New Issue
Block a user