fix: 修复签到成功图片不对的问题

This commit is contained in:
2025-12-21 20:44:09 +08:00
parent 70bc35cb64
commit 4f62b3d88b
7 changed files with 109 additions and 33 deletions

View File

@@ -1,12 +1,14 @@
from datetime import datetime
from pathlib import Path
from fastapi import APIRouter, Request, Response
from fastapi.responses import JSONResponse, RedirectResponse
from models import User
from services.services import XBXS
from starlette.templating import Jinja2Templates
from config import BASE_DIR
router = APIRouter()
templates = Jinja2Templates(directory="templates")
templates = Jinja2Templates(directory=str(BASE_DIR / "templates"))
@router.get("/")
@@ -23,6 +25,20 @@ async def index(request: Request):
)
@router.get("/logout")
async def logout(request: Request):
token = request.cookies.get("xbxs_token")
if token:
request.cookies.clear()
return templates.TemplateResponse(
"login.html",
{
"request": request,
"year": datetime.now().year,
},
)
@router.post("/login")
async def login(user: User, response: Response):
xbxs = XBXS()

View File

@@ -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="保存签到数据失败")