#!/usr/bin/env python # -*- coding: utf-8 -*- import os from fastapi import APIRouter, Query, Depends from fastapi.responses import FileResponse from models.user import SysUser 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"), current_user: SysUser = Depends(get_current_user)): filename = f"tmpl_{tmpl}.xlsx" tmpl_path = os.path.join(settings.TEMPLATE_PATH, filename) if not os.path.exists: return {"errcode": 400, "mess": "模板不存在!"} return FileResponse(tmpl_path, filename=filename)