mirror of
https://github.com/timothymiller/cloudflare-ddns.git
synced 2026-03-21 14:38:56 -03:00
Deduplicate IPs before DNS record update
Remove duplicate IPs before updating DNS records to ensure stable input. Signed-off-by: DaRK AnGeL <28630321+masterwishx@users.noreply.github.com>
This commit is contained in:
@@ -24,6 +24,7 @@ pub async fn update_once(
|
||||
|
||||
let mut all_ok = true;
|
||||
let mut messages = Vec::new();
|
||||
let mut notify = false; // NEW: track meaningful events
|
||||
|
||||
if config.legacy_mode {
|
||||
all_ok = update_legacy(config, ppfmt).await;
|
||||
@@ -65,8 +66,11 @@ pub async fn update_once(
|
||||
}
|
||||
|
||||
// Update DNS records (env var mode - domain-based)
|
||||
for (ip_type, domains) in &config.domains {
|
||||
let ips = detected_ips.get(ip_type).cloned().unwrap_or_default();
|
||||
for (ip_type, domains) in &config.domains {
|
||||
let mut ips = detected_ips.get(ip_type).cloned().unwrap_or_default();
|
||||
// FIX: remove duplicates so CloudflareHandle::set_ips sees stable input
|
||||
ips.sort();
|
||||
ips.dedup();
|
||||
let record_type = ip_type.record_type();
|
||||
|
||||
for domain_str in domains {
|
||||
@@ -108,6 +112,7 @@ pub async fn update_once(
|
||||
|
||||
match result {
|
||||
SetResult::Updated => {
|
||||
notify = true; // NEW
|
||||
let ip_strs: Vec<String> = ips.iter().map(|ip| ip.to_string()).collect();
|
||||
messages.push(Message::new_ok(&format!(
|
||||
"Updated {domain_str} -> {}",
|
||||
@@ -115,6 +120,7 @@ pub async fn update_once(
|
||||
)));
|
||||
}
|
||||
SetResult::Failed => {
|
||||
notify = true; // NEW
|
||||
all_ok = false;
|
||||
messages.push(Message::new_fail(&format!(
|
||||
"Failed to update {domain_str}"
|
||||
@@ -147,12 +153,14 @@ pub async fn update_once(
|
||||
|
||||
match result {
|
||||
SetResult::Updated => {
|
||||
notify = true; // NEW
|
||||
messages.push(Message::new_ok(&format!(
|
||||
"Updated WAF list {}",
|
||||
waf_list.describe()
|
||||
)));
|
||||
}
|
||||
SetResult::Failed => {
|
||||
notify = true; // NEW
|
||||
all_ok = false;
|
||||
messages.push(Message::new_fail(&format!(
|
||||
"Failed to update WAF list {}",
|
||||
@@ -164,13 +172,17 @@ pub async fn update_once(
|
||||
}
|
||||
}
|
||||
|
||||
// Send heartbeat
|
||||
let heartbeat_msg = Message::merge(messages.clone());
|
||||
heartbeat.ping(&heartbeat_msg).await;
|
||||
// Send heartbeat ONLY if something meaningful happened
|
||||
if notify {
|
||||
let heartbeat_msg = Message::merge(messages.clone());
|
||||
heartbeat.ping(&heartbeat_msg).await;
|
||||
}
|
||||
|
||||
// Send notifications
|
||||
let notifier_msg = Message::merge(messages);
|
||||
notifier.send(¬ifier_msg).await;
|
||||
// Send notifications ONLY when IP changed or failed
|
||||
if notify {
|
||||
let notifier_msg = Message::merge(messages);
|
||||
notifier.send(¬ifier_msg).await;
|
||||
}
|
||||
|
||||
all_ok
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user