Skip to content

Commit 8e72b28

Browse files
committed
add some minor fix
1 parent 5c35f8f commit 8e72b28

File tree

7 files changed

+240
-117
lines changed

7 files changed

+240
-117
lines changed

router-api/src/api/settings/auto_config.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,35 @@ pub async fn upload_config(
138138
)
139139
}
140140
};
141+
142+
// Delete all existing configurations
143+
// First delete all gateways
144+
if let Err(e) = gateway_queries::delete_all_gateways() {
145+
return HttpResponse::InternalServerError().json(serde_json::json!({
146+
"error": format!("Failed to delete existing gateways: {}", e)
147+
}));
148+
}
149+
150+
// Then delete all gateway nodes
151+
if let Err(e) = gwnode_queries::delete_all_gateway_nodes() {
152+
return HttpResponse::InternalServerError().json(serde_json::json!({
153+
"error": format!("Failed to delete existing gateway nodes: {}", e)
154+
}));
155+
}
156+
157+
// Then delete all proxy domains
158+
if let Err(e) = proxydomain_queries::delete_all_proxy_domains() {
159+
return HttpResponse::InternalServerError().json(serde_json::json!({
160+
"error": format!("Failed to delete existing proxy domains: {}", e)
161+
}));
162+
}
163+
164+
// Finally delete all proxies
165+
if let Err(e) = proxy_queries::delete_all_proxies() {
166+
return HttpResponse::InternalServerError().json(serde_json::json!({
167+
"error": format!("Failed to delete existing proxies: {}", e)
168+
}));
169+
}
141170

142171
// Process each proxy in the configuration
143172
let mut created_proxies = Vec::new();

router-api/src/api/settings/gateway_queries.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,21 @@ pub fn delete_gateway_by_id(id: &str) -> Result<bool, DatabaseError> {
375375
Ok(affected_rows > 0)
376376
}
377377

378+
/// Deletes all gateway configurations from the database
379+
///
380+
/// This function removes all gateway records from the database.
381+
/// It should be used with caution as it will remove all routing rules.
382+
///
383+
/// # Returns
384+
///
385+
/// * `Ok(())` - If all gateways were successfully deleted
386+
/// * `Err(DatabaseError)` - If there was an error deleting the gateways
387+
pub fn delete_all_gateways() -> Result<(), DatabaseError> {
388+
let db = get_connection()?;
389+
db.execute("DELETE FROM gateways", [])?;
390+
Ok(())
391+
}
392+
378393
/// Generates a new unique identifier for a gateway
379394
///
380395
/// This function creates a UUID v4 (random) string that can be used as the ID

router-api/src/api/settings/gwnode_queries.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,3 +484,18 @@ pub fn unbind_gateway_nodes_by_proxy_id(proxy_id: &str) -> Result<usize, Databas
484484

485485
Ok(affected_rows)
486486
}
487+
488+
/// Deletes all gateway node configurations from the database
489+
///
490+
/// This function removes all gateway node records from the database.
491+
/// It should be used with caution as it will remove all gateway nodes and their associated gateways.
492+
///
493+
/// # Returns
494+
///
495+
/// * `Ok(())` - If all gateway nodes were successfully deleted
496+
/// * `Err(DatabaseError)` - If there was an error deleting the gateway nodes
497+
pub fn delete_all_gateway_nodes() -> Result<(), DatabaseError> {
498+
let db = get_connection()?;
499+
db.execute("DELETE FROM gateway_nodes", [])?;
500+
Ok(())
501+
}

router-api/src/api/settings/proxy_queries.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,21 @@ pub fn delete_proxy_by_id(id: &str) -> Result<bool, DatabaseError> {
402402
Ok(affected_rows > 0)
403403
}
404404

405+
/// Deletes all proxy configurations from the database
406+
///
407+
/// This function removes all proxy records from the database.
408+
/// It should be used with caution as it will remove all proxy configurations.
409+
///
410+
/// # Returns
411+
///
412+
/// * `Ok(())` - If all proxies were successfully deleted
413+
/// * `Err(DatabaseError)` - If there was an error deleting the proxies
414+
pub fn delete_all_proxies() -> Result<(), DatabaseError> {
415+
let db = get_connection()?;
416+
db.execute("DELETE FROM proxies", [])?;
417+
Ok(())
418+
}
419+
405420
/// Generates a target address with a random available port
406421
///
407422
/// This function creates a localhost address (127.0.0.1) with a randomly selected

0 commit comments

Comments
 (0)