File size: 2,128 Bytes
a21c316 | 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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | use tauri::State;
use crate::commands::proxy::ProxyServiceState;
use std::collections::HashMap;
/// Bind an account to a specific proxy
#[tauri::command]
pub async fn bind_account_proxy(
state: State<'_, ProxyServiceState>,
account_id: String,
proxy_id: String,
) -> Result<(), String> {
let instance_lock = state.instance.read().await;
if let Some(instance) = instance_lock.as_ref() {
instance.axum_server.proxy_pool_manager.bind_account_to_proxy(account_id, proxy_id).await
} else {
Err("Service not running".to_string())
}
}
/// Unbind an account from its proxy
#[tauri::command]
pub async fn unbind_account_proxy(
state: State<'_, ProxyServiceState>,
account_id: String,
) -> Result<(), String> {
let instance_lock = state.instance.read().await;
if let Some(instance) = instance_lock.as_ref() {
instance.axum_server.proxy_pool_manager.unbind_account_proxy(account_id).await;
Ok(())
} else {
Err("Service not running".to_string())
}
}
/// Get the proxy binding for a specific account
#[tauri::command]
pub async fn get_account_proxy_binding(
state: State<'_, ProxyServiceState>,
account_id: String,
) -> Result<Option<String>, String> {
let instance_lock = state.instance.read().await;
if let Some(instance) = instance_lock.as_ref() {
Ok(instance.axum_server.proxy_pool_manager.get_account_binding(&account_id))
} else {
Err("Service not running".to_string())
}
}
/// Get all account proxy bindings
#[tauri::command]
pub async fn get_all_account_bindings(
state: State<'_, ProxyServiceState>,
) -> Result<HashMap<String, String>, String> {
let instance_lock = state.instance.read().await;
if let Some(instance) = instance_lock.as_ref() {
// Since get_all_bindings returns a DashMap ref or clone, we need to convert it to HashMap for serialization
// Assuming we add a method to ProxyPoolManager to get a snapshot
Ok(instance.axum_server.proxy_pool_manager.get_all_bindings_snapshot())
} else {
Err("Service not running".to_string())
}
}
|