chore(pre-commit): add pre-commit
This commit is contained in:
16
.pre-commit-config.yaml
Normal file
16
.pre-commit-config.yaml
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
default_install_hook_types: [pre-commit, prepare-commit-msg]
|
||||||
|
ci:
|
||||||
|
autofix_commit_msg: "chore(deps): auto fix by pre-commit hooks"
|
||||||
|
autofix_prs: true
|
||||||
|
autoupdate_branch: master
|
||||||
|
autoupdate_schedule: monthly
|
||||||
|
autoupdate_commit_msg: "chore(deps): auto update by pre-commit hooks"
|
||||||
|
repos:
|
||||||
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||||
|
rev: v0.12.2
|
||||||
|
hooks:
|
||||||
|
- id: ruff-check
|
||||||
|
args: [--fix]
|
||||||
|
stages: [pre-commit]
|
||||||
|
- id: ruff-format
|
||||||
|
stages: [pre-commit]
|
||||||
@@ -7,6 +7,8 @@ from sqlmodel import Field, Relationship, SQLModel
|
|||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from .user import User
|
from .user import User
|
||||||
|
|
||||||
|
|
||||||
class Team(SQLModel, table=True):
|
class Team(SQLModel, table=True):
|
||||||
__tablename__ = "teams" # pyright: ignore[reportAssignmentType]
|
__tablename__ = "teams" # pyright: ignore[reportAssignmentType]
|
||||||
|
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ import datetime
|
|||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import msgpack
|
|
||||||
from pydantic import Field, field_validator
|
|
||||||
|
|
||||||
from .signalr import MessagePackArrayModel
|
|
||||||
from .score import (
|
from .score import (
|
||||||
APIMod as APIModBase,
|
APIMod as APIModBase,
|
||||||
HitResult,
|
HitResult,
|
||||||
)
|
)
|
||||||
|
from .signalr import MessagePackArrayModel
|
||||||
|
|
||||||
|
import msgpack
|
||||||
|
from pydantic import Field, field_validator
|
||||||
|
|
||||||
|
|
||||||
class APIMod(APIModBase, MessagePackArrayModel): ...
|
class APIMod(APIModBase, MessagePackArrayModel): ...
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ class UserAchievement(BaseModel):
|
|||||||
return LazerUserAchievement(
|
return LazerUserAchievement(
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
achievement_id=self.achievement_id,
|
achievement_id=self.achievement_id,
|
||||||
achieved_at=self.achieved_at
|
achieved_at=self.achieved_at,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ async def oauth_token(
|
|||||||
raise HTTPException(status_code=400, detail="Refresh token required")
|
raise HTTPException(status_code=400, detail="Refresh token required")
|
||||||
|
|
||||||
# 验证刷新令牌
|
# 验证刷新令牌
|
||||||
token_record =await get_token_by_refresh_token(db, refresh_token)
|
token_record = await get_token_by_refresh_token(db, refresh_token)
|
||||||
if not token_record:
|
if not token_record:
|
||||||
raise HTTPException(status_code=401, detail="Invalid refresh token")
|
raise HTTPException(status_code=401, detail="Invalid refresh token")
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
|
||||||
class SignalRException(Exception):
|
class SignalRException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class InvokeException(SignalRException):
|
class InvokeException(SignalRException):
|
||||||
def __init__(self, message: str) -> None:
|
def __init__(self, message: str) -> None:
|
||||||
self.message = message
|
self.message = message
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from .hub import Hub
|
from .hub import Hub
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from .hub import Hub
|
from .hub import Hub
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -8,10 +8,8 @@ from .hub import Client, Hub
|
|||||||
class SpectatorHub(Hub):
|
class SpectatorHub(Hub):
|
||||||
async def BeginPlaySession(
|
async def BeginPlaySession(
|
||||||
self, client: Client, score_token: int, state: SpectatorState
|
self, client: Client, score_token: int, state: SpectatorState
|
||||||
) -> None:
|
) -> None: ...
|
||||||
...
|
|
||||||
|
|
||||||
async def SendFrameData(
|
async def SendFrameData(
|
||||||
self, client: Client, frame_data: FrameDataBundle
|
self, client: Client, frame_data: FrameDataBundle
|
||||||
) -> None:
|
) -> None: ...
|
||||||
...
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ from enum import IntEnum
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import msgpack
|
import msgpack
|
||||||
from pydantic import BaseModel, model_validator
|
|
||||||
|
|
||||||
SEP = b"\x1e"
|
SEP = b"\x1e"
|
||||||
|
|
||||||
@@ -18,6 +17,7 @@ class PacketType(IntEnum):
|
|||||||
PING = 6
|
PING = 6
|
||||||
CLOSE = 7
|
CLOSE = 7
|
||||||
|
|
||||||
|
|
||||||
class ResultKind(IntEnum):
|
class ResultKind(IntEnum):
|
||||||
ERROR = 1
|
ERROR = 1
|
||||||
VOID = 2
|
VOID = 2
|
||||||
|
|||||||
37
app/utils.py
37
app/utils.py
@@ -11,7 +11,6 @@ from app.database import (
|
|||||||
from app.models.user import (
|
from app.models.user import (
|
||||||
Country,
|
Country,
|
||||||
Cover,
|
Cover,
|
||||||
DailyChallengeStats,
|
|
||||||
GradeCounts,
|
GradeCounts,
|
||||||
Kudosu,
|
Kudosu,
|
||||||
Level,
|
Level,
|
||||||
@@ -24,9 +23,7 @@ from app.models.user import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
async def convert_db_user_to_api_user(
|
async def convert_db_user_to_api_user(db_user: DBUser, ruleset: str = "osu") -> User:
|
||||||
db_user: DBUser, ruleset: str = "osu"
|
|
||||||
) -> User:
|
|
||||||
"""将数据库用户模型转换为API用户模型(使用 Lazer 表)"""
|
"""将数据库用户模型转换为API用户模型(使用 Lazer 表)"""
|
||||||
|
|
||||||
# 从db_user获取基本字段值
|
# 从db_user获取基本字段值
|
||||||
@@ -71,7 +68,7 @@ async def convert_db_user_to_api_user(
|
|||||||
kudosu = Kudosu(available=0, total=0)
|
kudosu = Kudosu(available=0, total=0)
|
||||||
|
|
||||||
# 获取计数信息
|
# 获取计数信息
|
||||||
counts = LazerUserCounts(user_id=user_id)
|
# counts = LazerUserCounts(user_id=user_id)
|
||||||
|
|
||||||
# 转换统计信息
|
# 转换统计信息
|
||||||
statistics = Statistics(
|
statistics = Statistics(
|
||||||
@@ -176,21 +173,21 @@ async def convert_db_user_to_api_user(
|
|||||||
rank_history = RankHistory(mode=ruleset, data=rank_history_data)
|
rank_history = RankHistory(mode=ruleset, data=rank_history_data)
|
||||||
|
|
||||||
# 转换每日挑战统计
|
# 转换每日挑战统计
|
||||||
daily_challenge_stats = None
|
# daily_challenge_stats = None
|
||||||
if db_user.daily_challenge_stats:
|
# if db_user.daily_challenge_stats:
|
||||||
dcs = db_user.daily_challenge_stats
|
# dcs = db_user.daily_challenge_stats
|
||||||
daily_challenge_stats = DailyChallengeStats(
|
# daily_challenge_stats = DailyChallengeStats(
|
||||||
daily_streak_best=dcs.daily_streak_best,
|
# daily_streak_best=dcs.daily_streak_best,
|
||||||
daily_streak_current=dcs.daily_streak_current,
|
# daily_streak_current=dcs.daily_streak_current,
|
||||||
last_update=dcs.last_update,
|
# last_update=dcs.last_update,
|
||||||
last_weekly_streak=dcs.last_weekly_streak,
|
# last_weekly_streak=dcs.last_weekly_streak,
|
||||||
playcount=dcs.playcount,
|
# playcount=dcs.playcount,
|
||||||
top_10p_placements=dcs.top_10p_placements,
|
# top_10p_placements=dcs.top_10p_placements,
|
||||||
top_50p_placements=dcs.top_50p_placements,
|
# top_50p_placements=dcs.top_50p_placements,
|
||||||
user_id=dcs.user_id,
|
# user_id=dcs.user_id,
|
||||||
weekly_streak_best=dcs.weekly_streak_best,
|
# weekly_streak_best=dcs.weekly_streak_best,
|
||||||
weekly_streak_current=dcs.weekly_streak_current,
|
# weekly_streak_current=dcs.weekly_streak_current,
|
||||||
)
|
# )
|
||||||
|
|
||||||
# 转换最高排名
|
# 转换最高排名
|
||||||
rank_highest = None
|
rank_highest = None
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import time
|
|
||||||
|
|
||||||
from app.auth import get_password_hash
|
from app.auth import get_password_hash
|
||||||
from app.database import (
|
from app.database import (
|
||||||
@@ -23,7 +22,6 @@ async def create_sample_user():
|
|||||||
"""创建示例用户数据"""
|
"""创建示例用户数据"""
|
||||||
async with AsyncSession(engine) as session:
|
async with AsyncSession(engine) as session:
|
||||||
async with session.begin():
|
async with session.begin():
|
||||||
|
|
||||||
# 检查用户是否已存在
|
# 检查用户是否已存在
|
||||||
statement = select(User).where(User.name == "Googujiang")
|
statement = select(User).where(User.name == "Googujiang")
|
||||||
result = await session.execute(statement)
|
result = await session.execute(statement)
|
||||||
@@ -33,7 +31,7 @@ async def create_sample_user():
|
|||||||
return existing_user
|
return existing_user
|
||||||
|
|
||||||
# 当前时间戳
|
# 当前时间戳
|
||||||
current_timestamp = int(time.time())
|
# current_timestamp = int(time.time())
|
||||||
join_timestamp = int(datetime(2019, 11, 29, 17, 23, 13).timestamp())
|
join_timestamp = int(datetime(2019, 11, 29, 17, 23, 13).timestamp())
|
||||||
last_visit_timestamp = int(datetime(2025, 7, 18, 16, 31, 29).timestamp())
|
last_visit_timestamp = int(datetime(2025, 7, 18, 16, 31, 29).timestamp())
|
||||||
|
|
||||||
|
|||||||
@@ -85,5 +85,6 @@ reportIncompatibleVariableOverride = false
|
|||||||
[dependency-groups]
|
[dependency-groups]
|
||||||
dev = [
|
dev = [
|
||||||
"msgpack-types>=0.5.0",
|
"msgpack-types>=0.5.0",
|
||||||
|
"pre-commit>=4.2.0",
|
||||||
"ruff>=0.12.4",
|
"ruff>=0.12.4",
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user