File size: 1,532 Bytes
bbb1195
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
pub mod accounts;
pub mod config;
pub mod proxy;

use axum::{Router, routing::{get, post, delete}};

/// Create API routes (without state for management endpoints)
pub fn api_routes<S>() -> Router<S>
where
    S: Clone + Send + Sync + 'static,
{
    Router::new()
        // Account management
        .route("/api/accounts", get(accounts::list_accounts))
        .route("/api/accounts", post(accounts::add_account))
        .route("/api/accounts/:id", delete(accounts::delete_account))
        .route("/api/accounts/:id/quota", post(accounts::refresh_quota))
        .route("/api/accounts/refresh-all", post(accounts::refresh_all_quotas))
        .route("/api/accounts/current", get(accounts::get_current_account))
        .route("/api/accounts/:id/set-current", post(accounts::set_current_account))

        // Configuration management
        .route("/api/config", get(config::load_config))
        .route("/api/config", post(config::save_config))

        // Proxy management
        .route("/api/proxy/status", get(proxy::get_proxy_status))
        .route("/api/proxy/mapping", post(proxy::update_model_mapping))
        .route("/api/proxy/restart", post(proxy::restart_proxy))
        .route("/api/proxy/generate-key", post(proxy::generate_api_key))

        // Health check
        .route("/api/health", get(health_check))
}

/// Health check endpoint
async fn health_check() -> axum::Json<serde_json::Value> {
    axum::Json(serde_json::json!({
        "status": "ok",
        "version": env!("CARGO_PKG_VERSION")
    }))
}