diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a735cdea..bd6b0b8e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,7 +2,7 @@ name: Release # Publish a mod build on every version tag. Every release carries both a # versioned jar and a stable `lovisual.jar`, so the site's one-click download -# link (releases/latest/download/lovisual.jar) always resolves. +# link (the site serves lovisual.jar from our own server) always resolves. on: push: diff --git a/README.md b/README.md index 07277201..67fff8c5 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Open-source Minecraft utility client **and** the platform around it - website, cloud config sharing, and a Rust backend. -Developed and maintained by [loki5512344](https://github.com/loki5512344). +Developed and maintained by [loki5512344ss](https://github.com/loki5512344ss). ![Release](https://img.shields.io/gitea/v/release/boba/LoVisual?gitea_url=https%3A%2F%2Fgit.wihuk.pro&style=flat-square&color=blue) ![Java](https://img.shields.io/badge/Java-25+-orange?style=flat-square&logo=openjdk&logoColor=white) @@ -12,7 +12,7 @@ Developed and maintained by [loki5512344](https://github.com/loki5512344). ![React](https://img.shields.io/badge/Frontend-React%20%2B%20Vite-61dafb?style=flat-square&logo=react&logoColor=white) ![License](https://img.shields.io/badge/license-GPLv3-blue?style=flat-square&logo=gnu&logoColor=white) -**[⬇ Download the mod](https://git.wihuk.pro/boba/LoVisual/releases/latest/download/lovisual.jar)** · [Releases](https://git.wihuk.pro/boba/LoVisual/releases) +**[⬇ Download the mod](https://visual.loki-code.dev/download)** · [Releases](https://git.wihuk.pro/boba/LoVisual/releases) [English](#english) | [Русский](#русский) diff --git a/backend/accounts-service/src/accounts/repo.rs b/backend/accounts-service/src/accounts/repo.rs index adb4e8dd..0249bbd1 100644 --- a/backend/accounts-service/src/accounts/repo.rs +++ b/backend/accounts-service/src/accounts/repo.rs @@ -61,6 +61,17 @@ pub async fn set_avatar(pool: &PgPool, account_id: Uuid, s3_key: &str) -> Result Ok(()) } +/// Deletes the `avatars` row for one account. Returns `true` when a row existed +/// (so the caller can decide whether to also delete the S3 object) and `false` +/// when the user simply had no avatar — the API still treats that as success. +pub async fn clear_avatar(pool: &PgPool, account_id: Uuid) -> Result { + let result = sqlx::query("DELETE FROM avatars WHERE account_id = $1") + .bind(account_id) + .execute(pool) + .await?; + Ok(result.rows_affected() > 0) +} + /// Avatar reference for one account: its storage key plus an `uploaded_at` /// version (epoch seconds) used to cache-bust the served image URL. pub async fn avatar_ref( diff --git a/backend/accounts-service/src/avatars/handlers.rs b/backend/accounts-service/src/avatars/handlers.rs index 8c783f42..53a9d95b 100644 --- a/backend/accounts-service/src/avatars/handlers.rs +++ b/backend/accounts-service/src/avatars/handlers.rs @@ -70,6 +70,28 @@ pub async fn upload( })) } +/// DELETE /avatars — clears the caller's avatar. Removes the DB row and, if one +/// existed, the S3 object. Always returns 204, including when the user had no +/// avatar: the operation is idempotent, matching how the frontend's "Remove +/// avatar" button should behave after a successful click. +pub async fn delete( + State(state): State, + identity: GatewayIdentity, +) -> Result { + let account_id = identity.account_id; + let existed = repo::clear_avatar(&state.pool, account_id).await?; + if existed { + let key = format!("avatars/{account_id}.png"); + // S3 delete is best-effort: if MinIO is unreachable we already committed + // the DB row removal, and the object becomes orphaned but not served (the + // serve handler looks up keys via the DB, not directly). + if let Err(err) = state.storage.delete(&key).await { + tracing::warn!("avatar S3 delete failed for {account_id}: {err}"); + } + } + Ok(StatusCode::NO_CONTENT.into_response()) +} + /// Only serve the keys this service writes: `avatars/.png`. /// Anything else (traversal, other buckets/paths) is a 404. The gateway blocks /// dot-segments upstream, but the service validates independently. diff --git a/backend/accounts-service/src/avatars/storage.rs b/backend/accounts-service/src/avatars/storage.rs index 1a33bc57..3a0644e9 100644 --- a/backend/accounts-service/src/avatars/storage.rs +++ b/backend/accounts-service/src/avatars/storage.rs @@ -51,4 +51,17 @@ impl S3Storage { let aggregated = out.body.collect().await?; Ok(aggregated.into_bytes().to_vec()) } + + /// Deletes the object at `key`. MinIO's DeleteObject is idempotent — deleting + /// a missing key returns Ok. Callers on the app layer are expected to run + /// this only after a matching DB row existed, so a stray 404 here is silent. + pub async fn delete(&self, key: &str) -> anyhow::Result<()> { + self.client + .delete_object() + .bucket(&self.bucket) + .key(key) + .send() + .await?; + Ok(()) + } } diff --git a/backend/accounts-service/src/lib.rs b/backend/accounts-service/src/lib.rs index d020ba24..2d12f82d 100644 --- a/backend/accounts-service/src/lib.rs +++ b/backend/accounts-service/src/lib.rs @@ -89,6 +89,7 @@ pub fn build_app_with_mail(pool: sqlx::PgPool, cfg: &Config, mail: auth::reset:: let avatar_routes = Router::new() .route("/avatars", post(avatars::handlers::upload)) + .route("/avatars", axum::routing::delete(avatars::handlers::delete)) // Public avatar read served back through the gateway; the `{*key}` // wildcard is the storage key (`avatars/.png`). .route("/media/{*key}", get(avatars::handlers::serve)) diff --git a/backend/accounts-service/tests/avatar_upload.rs b/backend/accounts-service/tests/avatar_upload.rs index 85291d70..215584cb 100644 --- a/backend/accounts-service/tests/avatar_upload.rs +++ b/backend/accounts-service/tests/avatar_upload.rs @@ -121,3 +121,78 @@ async fn upload_without_identity_is_401() { .await .assert_status(StatusCode::UNAUTHORIZED); } + +#[tokio::test] +async fn delete_removes_the_row_and_returns_204() { + common::init_test_logging(); + common::ensure_avatar_bucket().await; + let pool = common::test_pool().await; + let server = common::test_server(accounts_service::build_app( + pool.clone(), + &common::test_config(), + )); + let (account_id, email) = common::register_account(&server).await; + + server + .post("/avatars") + .add_header(ACCOUNT_ID_HEADER, account_id.to_string()) + .multipart(form(png_bytes())) + .await + .assert_status_ok(); + + server + .delete("/avatars") + .add_header(ACCOUNT_ID_HEADER, account_id.to_string()) + .await + .assert_status(StatusCode::NO_CONTENT); + + let count: i64 = sqlx::query_as::<_, (i64,)>("SELECT COUNT(*) FROM avatars WHERE account_id = $1") + .bind(account_id) + .fetch_one(&pool) + .await + .unwrap() + .0; + assert_eq!(count, 0); + + sqlx::query("DELETE FROM accounts WHERE lower(email) = $1") + .bind(email.to_lowercase()) + .execute(&pool) + .await + .unwrap(); +} + +#[tokio::test] +async fn delete_without_avatar_is_idempotent() { + let pool = common::test_pool().await; + let server = common::test_server(accounts_service::build_app( + pool.clone(), + &common::test_config(), + )); + let (account_id, email) = common::register_account(&server).await; + + server + .delete("/avatars") + .add_header(ACCOUNT_ID_HEADER, account_id.to_string()) + .await + .assert_status(StatusCode::NO_CONTENT); + + sqlx::query("DELETE FROM accounts WHERE lower(email) = $1") + .bind(email.to_lowercase()) + .execute(&pool) + .await + .unwrap(); +} + +#[tokio::test] +async fn delete_without_identity_is_401() { + let pool = common::test_pool().await; + let server = common::test_server(accounts_service::build_app( + pool.clone(), + &common::test_config(), + )); + + server + .delete("/avatars") + .await + .assert_status(StatusCode::UNAUTHORIZED); +} diff --git a/backend/deploy/nginx-lovisual-downloads.conf b/backend/deploy/nginx-lovisual-downloads.conf new file mode 100644 index 00000000..7c312800 --- /dev/null +++ b/backend/deploy/nginx-lovisual-downloads.conf @@ -0,0 +1,2 @@ +# Per-client-IP connection counter for the capped jar download (see the site conf). +limit_conn_zone $binary_remote_addr zone=lv_downloads:10m; diff --git a/backend/deploy/nginx-visual.loki-code.dev.conf b/backend/deploy/nginx-visual.loki-code.dev.conf index 133701b4..20f0b15f 100644 --- a/backend/deploy/nginx-visual.loki-code.dev.conf +++ b/backend/deploy/nginx-visual.loki-code.dev.conf @@ -18,6 +18,23 @@ server { add_header Cache-Control "public, max-age=60" always; } + # The mod jar is served by nginx itself (not through the gateway) so the + # speed can be capped: ~6 Mbit/s per connection and at most 2 connections + # per client IP keep a flood of downloads from saturating the link. + location = /api/downloads/lovisual.jar { + alias /opt/lovisual/backend/downloads/lovisual.jar; + default_type application/java-archive; + add_header Content-Disposition 'attachment; filename="lovisual.jar"' always; + limit_rate 750k; + limit_conn lv_downloads 2; + limit_conn_status 429; + } + + location = /api/downloads/lovisual.jar.sha256 { + alias /opt/lovisual/backend/downloads/lovisual.jar.sha256; + default_type text/plain; + } + location /api/ { proxy_pass http://127.0.0.1:8080/; proxy_http_version 1.1; diff --git a/backend/gateway/PLAN.md b/backend/gateway/PLAN.md index 1724a1d6..85fbff12 100644 --- a/backend/gateway/PLAN.md +++ b/backend/gateway/PLAN.md @@ -2340,7 +2340,7 @@ git commit -m "feat(gateway): CORS for the site origin; docs for gateway and int ### Task 12: Easter eggs in the gateway - `.env` honeypot — done together with the dot-segment fix (see `.superpowers` fix list; commit "feat(gateway): .env honeypot easter egg for traversal scanners"). -- `GET /coffee` (any method) → `418 I'm a teapot`, `text/plain; charset=utf-8`: «Я чайник. Кофе не варю, зато LoVisual бесплатный: https://github.com/loki5512344/LoVisual-/releases». Handled in the gateway before identity/rate limits, not forwarded. Test + commit `feat(gateway): 418 teapot at /coffee`. +- `GET /coffee` (any method) → `418 I'm a teapot`, `text/plain; charset=utf-8`: «Я чайник. Кофе не варю, зато LoVisual бесплатный: https://github.com/loki5512344ss/LoVisual/releases». Handled in the gateway before identity/rate limits, not forwarded. Test + commit `feat(gateway): 418 teapot at /coffee`. --- diff --git a/backend/gateway/src/guard/honeypot.rs b/backend/gateway/src/guard/honeypot.rs index c8ebd46a..09617ec3 100644 --- a/backend/gateway/src/guard/honeypot.rs +++ b/backend/gateway/src/guard/honeypot.rs @@ -13,7 +13,7 @@ JWT_SECRET=nice_try_skiddie_tvoy_ip_uzhe_v_bane INTERNAL_KEY=0000-0000-0000-0000-otvali ADMIN_PASSWORD=hunter2 S3_SECRET_KEY=lovisual_luchshe_chem_tvoy_chit -# P.S. лучше скачай мод: https://github.com/loki5512344/LoVisual-/releases +# P.S. лучше скачай мод: https://github.com/loki5512344ss/LoVisual/releases "; /// Any segment named `.env` or `.env.` (dots may be `%2e`-encoded). diff --git a/backend/gateway/src/guard/mod.rs b/backend/gateway/src/guard/mod.rs index 4942e08d..ea840ac3 100644 --- a/backend/gateway/src/guard/mod.rs +++ b/backend/gateway/src/guard/mod.rs @@ -44,7 +44,7 @@ pub fn is_ambiguous(path: &str) -> bool { }) } -const TEAPOT: &str = "Я чайник. Кофе не варю, зато LoVisual бесплатный: https://github.com/loki5512344/LoVisual-/releases\n"; +const TEAPOT: &str = "Я чайник. Кофе не варю, зато LoVisual бесплатный: https://github.com/loki5512344ss/LoVisual/releases\n"; fn teapot() -> Response { ( diff --git a/frontend/PLAN.md b/frontend/PLAN.md index 5301aeef..76a39a4b 100644 --- a/frontend/PLAN.md +++ b/frontend/PLAN.md @@ -1154,7 +1154,7 @@ Replaces the Task 5 landing body (keep `CommandHero`'s chat line — it becomes - `DownloadPage` (`/download`): big button, requirements block (Minecraft 26.2, Fabric Loader 0.19.4+, Fabric API; optional Sodium/Iris — values in the download dictionary, sourced from `mod/gradle.properties`), 3-step install guide (real sequence: скачать → положить в `mods` → запустить с профилем Fabric), then `ReleaseNotes`. - [ ] **Step 1: CI workflow** (no test; validate with `actionlint` if available, otherwise careful review). Tagging/pushing is the owner's action — do not push tags. -- [ ] **Step 2: Failing tests** — button href equals `https://github.com/loki5512344/LoVisual-/releases/latest/download/lovisual.jar` (with `vi.stubEnv('VITE_GITHUB_REPO', …)`); release notes render Markdown headings and do NOT render a raw `