gitdataai/libs/api/admin/mod.rs
ZhenYi fb91f5a6c5 feat(admin): add admin panel with billing alerts and model sync
- Add libs/api/admin with admin API endpoints:
  sync models, workspace credit, billing alert check
- Add workspace_alert_config model and alert service
- Add Session::no_op() for background tasks without user context
- Add admin/ Next.js admin panel (AI models, billing, workspaces, audit)
- Start billing alert background task every 30 minutes
2026-04-19 20:48:59 +08:00

51 lines
2.0 KiB
Rust

//! Admin API endpoints — protected by `x-admin-api-key` header.
//!
//! These endpoints are called by the Admin Dashboard (Next.js) to perform
//! platform-wide operations that bypass normal user-session authorization.
use actix_web::web;
pub mod alerts;
pub mod ai_models;
pub mod billing;
pub mod sync;
pub fn init_admin_routes(cfg: &mut web::ServiceConfig) {
cfg.service(
web::scope("/api/admin")
.route("/health", web::get().to(health_check))
.route("/ai/sync", web::post().to(sync::admin_sync_models))
.route("/alerts/check", web::post().to(alerts::admin_check_alerts))
.route(
"/workspaces/{slug}/add-credit",
web::post().to(billing::admin_workspace_add_credit),
)
// Provider CRUD
.route("/ai/providers", web::post().to(ai_models::admin_provider_create))
.route("/ai/providers/{id}", web::patch().to(ai_models::admin_provider_update))
.route("/ai/providers/{id}", web::delete().to(ai_models::admin_provider_delete))
// Model CRUD
.route("/ai/models", web::post().to(ai_models::admin_model_create))
.route("/ai/models/{id}", web::patch().to(ai_models::admin_model_update))
.route("/ai/models/{id}", web::delete().to(ai_models::admin_model_delete))
// Version CRUD
.route("/ai/versions", web::post().to(ai_models::admin_version_create))
.route("/ai/versions/{id}", web::patch().to(ai_models::admin_version_update))
.route("/ai/versions/{id}", web::delete().to(ai_models::admin_version_delete))
// Pricing update
.route("/ai/pricing/{id}", web::patch().to(ai_models::admin_pricing_update)),
);
}
#[utoipa::path(
get,
path = "/api/admin/health",
responses(
(status = 200, description = "Admin API is healthy"),
),
tag = "Admin"
)]
async fn health_check() -> impl actix_web::Responder {
actix_web::HttpResponse::Ok().json(serde_json::json!({ "ok": true }))
}