gemini / server /src /proxy /config.rs
yinming
feat: Antigravity API Proxy for HuggingFace Spaces
bbb1195
use serde::{Deserialize, Serialize};
/// Proxy service configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ProxyConfig {
/// Whether proxy service is enabled
pub enabled: bool,
/// Whether to allow LAN access
/// - false: localhost only 127.0.0.1 (default, privacy first)
/// - true: allow LAN access 0.0.0.0
#[serde(default)]
pub allow_lan_access: bool,
/// Listen port
pub port: u16,
/// API key
pub api_key: String,
/// Whether to auto start
pub auto_start: bool,
/// Anthropic model mapping (key: Claude model name, value: Gemini model name)
#[serde(default)]
pub anthropic_mapping: std::collections::HashMap<String, String>,
/// OpenAI model mapping (key: OpenAI model group, value: Gemini model name)
#[serde(default)]
pub openai_mapping: std::collections::HashMap<String, String>,
/// Custom exact model mapping (key: original model name, value: target model name)
#[serde(default)]
pub custom_mapping: std::collections::HashMap<String, String>,
/// API request timeout in seconds
#[serde(default = "default_request_timeout")]
pub request_timeout: u64,
/// Upstream proxy configuration
#[serde(default)]
pub upstream_proxy: UpstreamProxyConfig,
}
/// Upstream proxy configuration
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct UpstreamProxyConfig {
/// Whether enabled
pub enabled: bool,
/// Proxy URL (http://, https://, socks5://)
pub url: String,
}
impl Default for ProxyConfig {
fn default() -> Self {
Self {
enabled: false,
allow_lan_access: true, // Cloud deployment should allow external access
port: 7860, // HuggingFace Spaces default port
api_key: format!("sk-{}", uuid::Uuid::new_v4().simple()),
auto_start: true, // Auto start in cloud environment
anthropic_mapping: std::collections::HashMap::new(),
openai_mapping: std::collections::HashMap::new(),
custom_mapping: std::collections::HashMap::new(),
request_timeout: default_request_timeout(),
upstream_proxy: UpstreamProxyConfig::default(),
}
}
}
fn default_request_timeout() -> u64 {
120 // Default 120 seconds
}
impl ProxyConfig {
/// Get actual bind address
/// - allow_lan_access = false: return "127.0.0.1" (default, privacy first)
/// - allow_lan_access = true: return "0.0.0.0" (allow LAN access)
pub fn get_bind_address(&self) -> &str {
if self.allow_lan_access {
"0.0.0.0"
} else {
"127.0.0.1"
}
}
}