fix: 修复签到成功图片不对的问题
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from datetime import datetime
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
from typing import List
|
||||
from uuid import uuid4
|
||||
from fastapi import (
|
||||
@@ -16,9 +17,11 @@ from fastapi import (
|
||||
from fastapi.responses import HTMLResponse, RedirectResponse
|
||||
from starlette.templating import Jinja2Templates
|
||||
from services.services import XBXS
|
||||
from config import BASE_DIR
|
||||
from exceptions.unauthorized import UnauthorizedError
|
||||
|
||||
router = APIRouter()
|
||||
templates = Jinja2Templates(directory="templates")
|
||||
templates = Jinja2Templates(directory=str(BASE_DIR / "templates"))
|
||||
|
||||
|
||||
def get_xbxs(request: Request) -> XBXS:
|
||||
@@ -53,16 +56,21 @@ async def profile(
|
||||
request: Request,
|
||||
xbxs: XBXS = Depends(get_xbxs),
|
||||
):
|
||||
student = await xbxs.get_student_info_cached()
|
||||
|
||||
return templates.TemplateResponse(
|
||||
"profile.html",
|
||||
{
|
||||
"request": request,
|
||||
"student": student,
|
||||
"active": "profile",
|
||||
},
|
||||
)
|
||||
try:
|
||||
student = await xbxs.get_student_info_cached()
|
||||
return templates.TemplateResponse(
|
||||
"profile.html",
|
||||
{
|
||||
"request": request,
|
||||
"student": student,
|
||||
"active": "profile",
|
||||
},
|
||||
)
|
||||
except UnauthorizedError as e:
|
||||
raise HTTPException(
|
||||
status_code=401,
|
||||
detail=e.message,
|
||||
)
|
||||
|
||||
|
||||
@router.get("/sign")
|
||||
@@ -70,7 +78,13 @@ async def sign_list(
|
||||
request: Request,
|
||||
xbxs: XBXS = Depends(get_xbxs),
|
||||
):
|
||||
result = await xbxs.get_know_list()
|
||||
try:
|
||||
result = await xbxs.get_know_list()
|
||||
except UnauthorizedError as e:
|
||||
raise HTTPException(
|
||||
status_code=401,
|
||||
detail=e.message,
|
||||
)
|
||||
|
||||
rows = result.get("rows", [])
|
||||
|
||||
@@ -98,7 +112,13 @@ async def sign_detail(
|
||||
request: Request,
|
||||
xbxs: XBXS = Depends(get_xbxs),
|
||||
):
|
||||
know_detail = await xbxs.get_know(str(knowing_id))
|
||||
try:
|
||||
know_detail = await xbxs.get_know(str(knowing_id))
|
||||
except UnauthorizedError as e:
|
||||
raise HTTPException(
|
||||
status_code=401,
|
||||
detail=e.message,
|
||||
)
|
||||
|
||||
data = know_detail.get("data", {})
|
||||
# 获取具体的数据
|
||||
@@ -147,10 +167,13 @@ async def complete_sign(
|
||||
if not remark:
|
||||
raise HTTPException(status_code=400, detail="备注是必填项")
|
||||
|
||||
print(location, remark, know_id, images, address)
|
||||
|
||||
try:
|
||||
await xbxs.update_student_know(str(know_id), remark, address, location, images)
|
||||
except UnauthorizedError as e:
|
||||
raise HTTPException(
|
||||
status_code=401,
|
||||
detail=e.message,
|
||||
)
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail="保存签到数据失败")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user