60 Commits

Author SHA1 Message Date
MingxuanGame
8923d714a7 feat(client-verification): add client verification (#104)
New configurations:

- `CHECK_CLIENT_VERSION` enables the check (default=True)
- `CLIENT_VERSION_URLS` contains a chain of valid client hashes. [osu!](https://osu.ppy.sh/home/download) and [osu! GU](https://github.com/GooGuTeam/osu/releases) are valid by default. View [g0v0-client-versions](https://github.com/GooGuTeam/g0v0-client-versions) to learn how to support your own client.

---------

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2026-01-11 16:30:25 +08:00
pre-commit-ci[bot]
aa9387c53a chore(linter): auto fix by pre-commit hooks 2025-11-25 03:09:02 +00:00
咕谷酱
db430db01b fix(fetcher): handle token timeout gracefully 2025-11-25 11:08:51 +08:00
MingxuanGame
8f4a9d5fed feat(fetcher): use client_credentials grant type to avoid missing refresh token (#62)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-10-25 20:01:50 +08:00
咕谷酱
a10c07dc57 Align session verification logic with osu-web
Updated session verification method selection to match osu-web's State.php:36 logic, using SUPPORT_TOTP_VERIFICATION_VER for version checks and prioritizing TOTP when available. Added example environment files for osu-web-master to support local, dusk, and testing setups.
2025-10-12 03:34:38 +08:00
MingxuanGame
a32976857f feat(score): invalidate cache when pin/unpin/reorder scores 2025-10-08 06:12:12 +00:00
MingxuanGame
febc1d761f feat(user): implement user restrictions
## APIs Restricted for Restricted Users

A restricted user is blocked from performing the following actions, and will typically receive a `403 Forbidden` error:

*   **Chat & Notifications:**
    *   Sending any chat messages (public or private).
    *   Joining or leaving chat channels.
    *   Creating new PM channels.
*   **User Profile & Content:**
    *   Uploading a new avatar.
    *   Uploading a new profile cover image.
    *   Changing their username.
    *   Updating their userpage content.
*   **Scores & Gameplay:**
    *   Submitting scores in multiplayer rooms.
    *   Deleting their own scores (to prevent hiding evidence of cheating).
*   **Beatmaps:**
    *   Rating beatmaps.
    *   Taging beatmaps.
*   **Relationship:**
    *   Adding friends or blocking users.
    *   Removing friends or unblocking users.
*   **Teams:**
    *   Creating, updating, or deleting a team.
    *   Requesting to join a team.
    *   Handling join requests for a team they manage.
    *   Kicking a member from a team they manage.
*   **Multiplayer:**
    *   Creating or deleting multiplayer rooms.
    *   Joining or leaving multiplayer rooms.

## What is Invisible to Normal Users

*   **Leaderboards:**
    *   Beatmap leaderboards.
    *   Multiplayer (playlist) room leaderboards.
*   **User Search/Lists:**
    *   Restricted users will not appear in the results of the `/api/v2/users` endpoint.
    *   They will not appear in the list of a team's members.
*   **Relationship:**
    *   They will not appear in a user's friend list (`/friends`).
*   **Profile & History:**
    *   Attempting to view a restricted user's profile, events, kudosu history, or score history will result in a `404 Not Found` error, effectively making their profile invisible (unless the user viewing the profile is the restricted user themselves).
*   **Chat:**
    *   Normal users cannot start a new PM with a restricted user (they will get a `404 Not Found` error).
*   **Ranking:**
    *   Restricted users are excluded from any rankings.

### How to Restrict a User

Insert into `user_account_history` with `type=restriction`.

```sql
-- length is in seconds
INSERT INTO user_account_history (`description`, `length`, `permanent`, `timestamp`, `type`, `user_id`) VALUE ('some description', 86400, 0, '2025-10-05 01:00:00', 'RESTRICTION', 1);
```

---

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-10-06 11:10:25 +08:00
MingxuanGame
216d3ab3bf feat(redis): refactor Redis configuration to use multiple logical databases
- Updated default REDIS_URL to remove explicit /0 suffix
- Added dedicated Redis clients:
  - db0: general cache (redis_client)
  - db1: message cache (redis_message_client)
  - db2: binary storage (redis_binary_client)
  - db3: rate limiting (redis_rate_limit_client)
- Updated configuration, Docker files, and main startup lifecycle accordingly
- Replaced `get_redis()` usage in notification server with `redis_message_client`
2025-10-04 05:39:59 +00:00
MingxuanGame
c2bfafc67a refactor(message): replace synchronous Redis client with asynchronous client 2025-10-04 05:26:37 +00:00
MingxuanGame
dfd656f2fb style(project): remove from __future__ import annotations 2025-10-03 17:15:41 +00:00
MingxuanGame
d490239f46 chore(linter): update ruff rules 2025-10-03 15:46:53 +00:00
MingxuanGame
d23f32f08d refactor(log): refactor the whole project
format: {time:YYYY-MM-DD HH:mm:ss} [{level}] | {name} | {message}
{name} is:
- Uvicorn: log from uvicorn server (#228B22)
- Service: log from class of `app.service` (blue)
- Fetcher: log from fetchers (magenta)
- Task: log from `app.tasks` (#FFD700)
- System: log from `system_logger` (red)
- Normal: log from `log(name)` (#FFC1C1)
- Default: the module name of caller

if you are writing services or tasks, you can just call `logger.`, we will pack it with name `Service` or `Task`
if you want to print fetcher logs, system-related logs, or normal logs, use `logger = (fetcher_logger / system_logger / log)(name)`
2025-10-03 11:53:05 +00:00
MingxuanGame
346c2557cf refactor(api): use Annotated-style dependency injection 2025-10-03 05:41:31 +00:00
MingxuanGame
40670c094b feat(auth): support trusted device (#52)
New API to maintain sessions and devices:

- GET /api/private/admin/sessions
- DELETE /api/private/admin/sessions/{session_id}
- GET /api/private/admin/trusted-devices
- DELETE /api/private/admin/trusted-devices/{device_id}

Auth:

web clients request `/oauth/token` and `/api/v2/session/verify` with `X-UUID` header to save the client as trusted device.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-10-03 11:26:43 +08:00
MingxuanGame
f31056ced3 perf(score): divide score processing into small parts and make them run in background
resolve #47
2025-10-02 14:30:57 +00:00
MingxuanGame
017b058e63 chore(linter): make linter happy 2025-09-30 07:57:08 +00:00
咕谷酱
4017f2af73 fix:修复音频代理缓存报错 2025-09-29 21:22:06 +08:00
咕谷酱
3a434ee02c 修复部分报错 2025-09-24 03:04:09 +08:00
咕谷酱
edbf01daa1 添加谱面查询缓存 2025-09-23 01:34:43 +08:00
MingxuanGame
1527e23b43 feat(session-verify): 添加 TOTP 支持 (#34)
* chore(deps): add pyotp

* feat(auth): implement TOTP verification

feat(auth): implement TOTP verification and email verification services

- Added TOTP keys management with a new database model `TotpKeys`.
- Introduced `EmailVerification` and `LoginSession` models for email verification.
- Created `verification_service` to handle email verification logic and TOTP processes.
- Updated user response models to include session verification methods.
- Implemented routes for TOTP creation, verification, and fallback to email verification.
- Enhanced login session management to support new location checks and verification methods.
- Added migration script to create `totp_keys` table in the database.

* feat(config): update config example

* docs(totp): complete creating TOTP flow

* refactor(totp): resolve review

* feat(api): forbid unverified request

* fix(totp): trace session by token id to avoid other sessions are forbidden

* chore(linter): make pyright happy

* fix(totp): only mark sessions with a specified token id
2025-09-21 19:50:11 +08:00
MingxuanGame
19f94fffbb feat(api): 支持 x-api-version (#29)
* feat(relationship): support legacy-compatible response format

* feat(score): add support for legacy score response format in API

* fix(score): avoid missing greenlet

* fix(score): fix missing field for model validation

* feat(user): apply legacy score format for user

* feat(api): use `int` to hint `APIVersion`
2025-09-14 14:09:53 +08:00
MingxuanGame
fdb08fe31f fix(rate-limit): apply on router to avoid TypeError on ws endpoint 2025-08-28 16:41:33 +00:00
MingxuanGame
598fcc8b38 refactor(project): make pyright & ruff happy 2025-08-22 08:21:52 +00:00
咕谷酱
ce465aa049 整理代码 2025-08-22 05:57:28 +08:00
咕谷酱
1fe603f416 add message redis 2025-08-22 01:49:03 +08:00
咕谷酱
822d7c6377 Add grade hot cache 2025-08-21 23:35:25 +08:00
MingxuanGame
068697355f feat(achievement): support obtain achievements 2025-08-21 08:50:16 +00:00
MingxuanGame
ce756c354b fix(statistics): run recalculate independently 2025-08-19 13:45:12 +00:00
MingxuanGame
1c65b21bb9 refactor(app): update database code 2025-08-18 16:37:30 +00:00
咕谷酱
041e2a0781 Add beatmapsets Download load balancing 2025-08-18 02:58:40 +08:00
MingxuanGame
86bea5d4b5 chore(lint): make ruff happy 2025-08-17 16:59:05 +00:00
咕谷酱
6e496a1123 add ip log 2025-08-18 00:23:57 +08:00
咕谷酱
de0c86f4a2 add geoip 2025-08-17 23:56:46 +08:00
MingxuanGame
caa4fe01af fix(request): incorrectly parse body for a form 2025-08-16 17:33:57 +00:00
MingxuanGame
87a3928e20 docs(chat): add API docs 2025-08-16 15:35:27 +00:00
MingxuanGame
f992e4cc71 feat(chat): support public channel chat 2025-08-16 05:29:16 +00:00
MingxuanGame
a8906b8194 feat(v1-api): support api v1 2025-08-14 09:11:53 +00:00
MingxuanGame
7817b7c59a feat(oauth): support client credentials grant 2025-08-13 14:12:29 +00:00
MingxuanGame
50b8d9a914 fix(database): extend pools (sentry-11) 2025-08-13 08:43:37 +00:00
MingxuanGame
39e7309d01 docs(api): more exactly 2025-08-12 16:17:50 +00:00
MingxuanGame
cf3a6bbd21 feat(storage): support cloud storage 2025-08-12 03:58:06 +00:00
MingxuanGame
867b99cca5 fix(database): fix cross-session user (current_user doesn't belong to get_db) 2025-08-11 14:01:37 +00:00
MingxuanGame
6e71141146 feat(developer): support custom OAuth 2.0 client 2025-08-11 12:33:31 +00:00
MingxuanGame
f165ae5dc3 refactor(config): use pydantic-settings 2025-08-10 05:38:28 +00:00
MingxuanGame
cf45070c2c refactor(database): use alembic to maintain the whole database 2025-08-10 04:33:03 +00:00
MingxuanGame
5fe3f36055 feat(daily-challenge): complete daily-challenge 2025-08-09 14:34:46 +00:00
MingxuanGame
8531e67423 feat(redis): add subscriber for pub/sub mode 2025-08-09 12:09:23 +00:00
MingxuanGame
832a6fc95d feat(daily-challenge): simple implement 2025-08-09 11:18:29 +00:00
MingxuanGame
c5fc6afc18 feat(redis): use asyncio 2025-07-31 14:38:10 +00:00
MingxuanGame
be401e8885 refactor(database): 优化数据库关联对象的载入 (#10) 2025-07-31 20:11:22 +08:00