Skip to content

Commit aea583a

Browse files
committed
1.0
1 parent b264c4d commit aea583a

File tree

364 files changed

+36982
-109
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

364 files changed

+36982
-109
lines changed

apis/article.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ async def get_articles(
1212
):
1313
session = DB.get_session()
1414
try:
15+
from sqlalchemy import text
1516
articles = session.execute(
16-
"SELECT * FROM articles LIMIT :limit OFFSET :offset",
17+
text("SELECT * FROM articles LIMIT :limit OFFSET :offset"),
1718
{"limit": limit, "offset": offset}
1819
).fetchall()
1920
return {"code": 0, "data": articles}

apis/auth.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,12 @@ async def refresh_token(current_user: dict = Depends(get_current_user)):
3434
access_token = create_access_token(
3535
data={"sub": current_user["username"]}, expires_delta=access_token_expires
3636
)
37-
return {"access_token": access_token, "token_type": "bearer"}
37+
return {"access_token": access_token, "token_type": "bearer"}
38+
39+
@router.get("/verify", summary="验证Token有效性")
40+
async def verify_token(current_user: dict = Depends(get_current_user)):
41+
"""验证当前token是否有效"""
42+
return {
43+
"is_valid": True,
44+
"user": current_user["username"]
45+
}

apis/user.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from fastapi import APIRouter, Depends, HTTPException, status
1+
from fastapi import APIRouter, Depends, HTTPException, status, UploadFile, File
22
from datetime import datetime
33
from core.auth import get_current_user
44
from core.db import DB
55
from core.models import User as DBUser
66
from core.auth import pwd_context
7-
from .ver import API_VERSION
7+
import os
88

9-
router = APIRouter(prefix=f"{API_VERSION}/user", tags=["用户管理"])
9+
router = APIRouter(prefix="/wx/user", tags=["用户管理"])
1010

1111
@router.get("", summary="获取用户信息")
1212
async def get_user_info(current_user: dict = Depends(get_current_user)):
@@ -64,4 +64,29 @@ async def update_user_info(
6464
detail=str(e)
6565
)
6666
finally:
67-
session.close()
67+
session.close()
68+
69+
@router.post("/avatar", summary="上传用户头像")
70+
async def upload_avatar(
71+
file: UploadFile = File(...),
72+
current_user: dict = Depends(get_current_user)
73+
):
74+
"""处理用户头像上传"""
75+
try:
76+
# 确保头像目录存在
77+
os.makedirs("static/avatars", exist_ok=True)
78+
79+
# 保存文件
80+
file_path = f"static/avatars/{current_user['username']}.jpg"
81+
with open(file_path, "wb") as buffer:
82+
buffer.write(await file.read())
83+
84+
return {
85+
"code": 0,
86+
"url": f"/avatars/{current_user['username']}.jpg"
87+
}
88+
except Exception as e:
89+
raise HTTPException(
90+
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
91+
detail=f"头像上传失败: {str(e)}"
92+
)

apis/wechat.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ async def get_mp_detail(
2020
):
2121
session = DB.get_session()
2222
try:
23+
from sqlalchemy import text
2324
mp = session.execute(
24-
"SELECT * FROM mps WHERE mp_id = :id",
25+
text("SELECT * FROM mps WHERE mp_id = :id"),
2526
{"id": mp_id}
2627
).fetchone()
2728
if not mp:

node_modules/.yarn-integrity

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/asynckit/LICENSE

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/asynckit/README.md

Lines changed: 233 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)