12345678910111213141516171819202122232425262728 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import os
- from fastapi import APIRouter, Query, Depends
- from fastapi.responses import FileResponse
- from models.user import Admin
- from utils.depends import get_current_user
- from core.config import settings
- router = APIRouter()
- @router.get("/templates", summary="模板下载")
- async def download(tmpl: str = Query(..., description="模板类型,取值:teacher/student/work/exam"),
- current_user: Admin = Depends(get_current_user)):
- if tmpl in ["teacher", "student"]:
- filename = f"tmpl_{tmpl}.xlsx"
- else:
- filename = f"tmpl_category_{tmpl}.xlsx"
- tmpl_path = os.path.join(settings.TEMPLATE_PATH, filename)
- if not os.path.exists(tmpl_path):
- return {"errcode": 400, "mess": "模板不存在!"}
- return FileResponse(tmpl_path, filename=filename)
|