From 6d091fbebef58964f32298a44223779fc278582a Mon Sep 17 00:00:00 2001 From: DaLaw2 Date: Sun, 19 Apr 2026 14:35:20 +0800 Subject: [PATCH] fix(http): unify model upload + status under /ml/models scope MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The upload route was registered at `/api/models/upload` while the status / dormant routes lived at `/api/ml/models/current`. Doc comments already advertised the unified `/api/ml/models/upload` path. Move the upload scope from `/models` to `/ml/models` so: * the entire ML model lifecycle (status, dormant, upload) lives under one URL subtree, matching the doc comments; * the RBAC scope mapping in middleware.rs (`/api/ml/` → `ai_detection`) now also covers upload, layered on top of the handler-level `users:admin` check; * frontend clients can build the model URLs from a single base path. Also fix the stale `GET /api/models/current` reference in `model_source.rs` ModelSourceStatus doc comment. Co-Authored-By: Claude Opus 4.7 (1M context) --- net-guardia/src/adapter/http/model_upload.rs | 6 +++++- net-guardia/src/model/detection/model_source.rs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/net-guardia/src/adapter/http/model_upload.rs b/net-guardia/src/adapter/http/model_upload.rs index 5bec3af..17c9305 100644 --- a/net-guardia/src/adapter/http/model_upload.rs +++ b/net-guardia/src/adapter/http/model_upload.rs @@ -120,7 +120,11 @@ impl Drop for PromoteGuard<'_> { } pub fn initialize() -> Scope { - web::scope("/models").route("/upload", web::post().to(upload)) + // Mounted under `/ml/models/upload` so the entire ML model lifecycle + // (status, dormant, upload) lives under one URL subtree. The peer + // `/ml/models/current` GET/DELETE routes live in `ml::initialize()`; + // actix dispatches each path to whichever scope owns it. + web::scope("/ml/models").route("/upload", web::post().to(upload)) } /// `POST /api/ml/models/upload` — multipart with `manifest` (YAML text), diff --git a/net-guardia/src/model/detection/model_source.rs b/net-guardia/src/model/detection/model_source.rs index d0f0445..9b43325 100644 --- a/net-guardia/src/model/detection/model_source.rs +++ b/net-guardia/src/model/detection/model_source.rs @@ -44,7 +44,7 @@ impl ModelInfo { } /// Wire-format ML source status. Broadcast to frontend; returned by -/// `GET /api/models/current`. Serde-tagged so the frontend can discriminate +/// `GET /api/ml/models/current`. Serde-tagged so the frontend can discriminate /// on the `state` field. #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(tag = "state", rename_all = "snake_case")]