mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-08 01:06:59 +08:00
41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
import os
|
|
from http.client import HTTPException
|
|
|
|
from fastapi import APIRouter
|
|
from fastapi.responses import FileResponse
|
|
|
|
from apps.swagger.i18n import PLACEHOLDER_PREFIX
|
|
from common.core.config import settings
|
|
from common.core.file import FileRequest
|
|
|
|
router = APIRouter(tags=["System"], prefix="/system")
|
|
|
|
path = settings.EXCEL_PATH
|
|
|
|
|
|
@router.post("/download-fail-info", summary=f"{PLACEHOLDER_PREFIX}download-fail-info")
|
|
async def download_excel(req: FileRequest):
|
|
"""
|
|
根据文件路径下载 Excel 文件
|
|
"""
|
|
filename = req.file
|
|
file_path = os.path.join(path, filename)
|
|
|
|
# 检查文件是否存在
|
|
if not os.path.exists(file_path):
|
|
raise HTTPException(404, "File Not Exists")
|
|
|
|
# 检查文件是否是 Excel 文件
|
|
if not filename.endswith('_error.xlsx'):
|
|
raise HTTPException(400, "Only support _error.xlsx")
|
|
|
|
# 获取文件名
|
|
filename = os.path.basename(file_path)
|
|
|
|
# 返回文件
|
|
return FileResponse(
|
|
path=file_path,
|
|
filename=filename,
|
|
media_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
)
|