Skip to content

Commit ffdec44

Browse files
committed
fix: lost wechat oauth url generate route
1 parent 42986c8 commit ffdec44

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

maimai_py/api.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ class ChainResult(BaseModel):
9292
}
9393
}
9494

95+
class WechatOAuthResponse(BaseModel):
96+
url: str
97+
9598
class MaimaiRoutes:
9699
_client: MaimaiClient
97100
_with_curves: bool
@@ -125,8 +128,8 @@ def _dep_arcade_player(self, credentials: str):
125128

126129
def _dep_wechat_player(
127130
self,
128-
t: str = Query(..., alias="_t", description="_t in cookies"),
129-
user_id: str = Query(..., alias="userId", description="userId in cookies"),
131+
t: str = Query(..., alias="_t", description="_t in returned credentials dict"),
132+
user_id: str = Query(..., alias="userId", description="userId in returned credentials dict"),
130133
):
131134
return PlayerIdentifier(credentials=Cookies({"_t": t, "userId": user_id}))
132135

@@ -476,6 +479,30 @@ def _callback(to: dict, scores: MaimaiScores, err: BaseException | None, kwargs:
476479

477480
return router
478481

482+
def get_utils_route(self) -> APIRouter:
483+
"""Get a FastAPI APIRouter with routes for utility functions.
484+
485+
Returns:
486+
APIRouter: A FastAPI APIRouter with utility routes.
487+
"""
488+
router = APIRouter()
489+
490+
async def _get_wechat_oauth() -> WechatOAuthResponse:
491+
auth_url = await self._client.wechat()
492+
assert isinstance(auth_url, str)
493+
return WechatOAuthResponse(url=auth_url)
494+
495+
router.add_api_route(
496+
"/wechat_oauth",
497+
_get_wechat_oauth,
498+
name="get_wechat_oauth",
499+
methods=["GET"],
500+
response_model=WechatOAuthResponse,
501+
description=f"Get wechat offiaccount oauth2 auth url with protocal modified redirect_url (https to http).",
502+
)
503+
504+
return router
505+
479506

480507
if all([find_spec(p) for p in ["fastapi", "uvicorn", "typer"]]):
481508
import typer
@@ -522,6 +549,9 @@ async def lifespan(app: FastAPI):
522549
tags=["utils"],
523550
)
524551

552+
# other utils routes
553+
asgi_app.include_router(routes.get_utils_route(), prefix="/utils", tags=["utils"])
554+
525555
def main(
526556
host: Annotated[str, typer.Option(help="The host address to bind to.")] = "127.0.0.1",
527557
port: Annotated[int, typer.Option(help="The port number to bind to.")] = 8000,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "maimai-py"
3-
version = "1.3.7rc3"
3+
version = "1.3.7rc4"
44
description = "The definitive python wrapper for MaimaiCN."
55
authors = ["Usagi no Niku <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)