feat(sync): add configuration to control syncing & support sync immediately by API

This commit is contained in:
MingxuanGame
2025-10-05 03:44:46 +00:00
parent 8884f8993c
commit 1db34bf5c5
4 changed files with 140 additions and 98 deletions

View File

@@ -10,7 +10,7 @@ from app.service.beatmapset_update_service import get_beatmapset_update_service
from .router import router
from fastapi import Body, Depends, HTTPException
from fastapi import Body, Depends, HTTPException, Path, Query
from fastapi_limiter.depends import RateLimiter
from sqlmodel import col, exists, select
@@ -93,21 +93,24 @@ async def rate_beatmaps(
dependencies=[Depends(RateLimiter(times=50, hours=1))],
)
async def sync_beatmapset(
beatmapset_id: int,
beatmapset_id: Annotated[int, Path(..., description="谱面集ID")],
session: Database,
current_user: ClientUser,
immediate: Annotated[bool, Query(description="是否立即同步")] = False,
):
"""请求同步谱面集
请求将指定的谱面集从 Bancho 同步到服务器
请求发送后会加入同步队列,等待自动同步
默认情况下请求会加入同步队列,等待自动同步
若设置 `immediate=true`,会尝试立刻同步该谱面集。
速率限制:
- 每个用户每小时最多50次请求
参数:
- beatmapset_id: 谱面集ID
- immediate: 是否立即同步(默认 false
错误情况:
- 404: 找不到指定谱面集
@@ -115,4 +118,4 @@ async def sync_beatmapset(
current_beatmapset = (await session.exec(select(exists()).where(Beatmapset.id == beatmapset_id))).first()
if not current_beatmapset:
raise HTTPException(404, "Beatmapset Not Found")
await get_beatmapset_update_service().add_missing_beatmapset(beatmapset_id)
await get_beatmapset_update_service().add_missing_beatmapset(beatmapset_id, immediate)