mirror of
https://github.com/timothymiller/cloudflare-ddns.git
synced 2026-03-21 22:48:57 -03:00
@@ -167,6 +167,7 @@ pub fn parse_trace_ip(body: &str) -> Option<String> {
|
|||||||
async fn fetch_trace_ip(client: &Client, url: &str, timeout: Duration) -> Option<IpAddr> {
|
async fn fetch_trace_ip(client: &Client, url: &str, timeout: Duration) -> Option<IpAddr> {
|
||||||
let resp = client
|
let resp = client
|
||||||
.get(url)
|
.get(url)
|
||||||
|
.header("Host", "one.one.one.one")
|
||||||
.timeout(timeout)
|
.timeout(timeout)
|
||||||
.send()
|
.send()
|
||||||
.await
|
.await
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ pub async fn update_once(
|
|||||||
|
|
||||||
let mut all_ok = true;
|
let mut all_ok = true;
|
||||||
let mut messages = Vec::new();
|
let mut messages = Vec::new();
|
||||||
|
let mut notify = false; // NEW: track meaningful events
|
||||||
|
|
||||||
if config.legacy_mode {
|
if config.legacy_mode {
|
||||||
all_ok = update_legacy(config, ppfmt).await;
|
all_ok = update_legacy(config, ppfmt).await;
|
||||||
@@ -108,6 +109,7 @@ pub async fn update_once(
|
|||||||
|
|
||||||
match result {
|
match result {
|
||||||
SetResult::Updated => {
|
SetResult::Updated => {
|
||||||
|
notify = true; // NEW
|
||||||
let ip_strs: Vec<String> = ips.iter().map(|ip| ip.to_string()).collect();
|
let ip_strs: Vec<String> = ips.iter().map(|ip| ip.to_string()).collect();
|
||||||
messages.push(Message::new_ok(&format!(
|
messages.push(Message::new_ok(&format!(
|
||||||
"Updated {domain_str} -> {}",
|
"Updated {domain_str} -> {}",
|
||||||
@@ -115,6 +117,7 @@ pub async fn update_once(
|
|||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
SetResult::Failed => {
|
SetResult::Failed => {
|
||||||
|
notify = true; // NEW
|
||||||
all_ok = false;
|
all_ok = false;
|
||||||
messages.push(Message::new_fail(&format!(
|
messages.push(Message::new_fail(&format!(
|
||||||
"Failed to update {domain_str}"
|
"Failed to update {domain_str}"
|
||||||
@@ -147,12 +150,14 @@ pub async fn update_once(
|
|||||||
|
|
||||||
match result {
|
match result {
|
||||||
SetResult::Updated => {
|
SetResult::Updated => {
|
||||||
|
notify = true; // NEW
|
||||||
messages.push(Message::new_ok(&format!(
|
messages.push(Message::new_ok(&format!(
|
||||||
"Updated WAF list {}",
|
"Updated WAF list {}",
|
||||||
waf_list.describe()
|
waf_list.describe()
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
SetResult::Failed => {
|
SetResult::Failed => {
|
||||||
|
notify = true; // NEW
|
||||||
all_ok = false;
|
all_ok = false;
|
||||||
messages.push(Message::new_fail(&format!(
|
messages.push(Message::new_fail(&format!(
|
||||||
"Failed to update WAF list {}",
|
"Failed to update WAF list {}",
|
||||||
@@ -164,13 +169,17 @@ pub async fn update_once(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send heartbeat
|
// Send heartbeat ONLY if something meaningful happened
|
||||||
let heartbeat_msg = Message::merge(messages.clone());
|
if notify {
|
||||||
heartbeat.ping(&heartbeat_msg).await;
|
let heartbeat_msg = Message::merge(messages.clone());
|
||||||
|
heartbeat.ping(&heartbeat_msg).await;
|
||||||
|
}
|
||||||
|
|
||||||
// Send notifications
|
// Send notifications ONLY when IP changed or failed
|
||||||
let notifier_msg = Message::merge(messages);
|
if notify {
|
||||||
notifier.send(¬ifier_msg).await;
|
let notifier_msg = Message::merge(messages);
|
||||||
|
notifier.send(¬ifier_msg).await;
|
||||||
|
}
|
||||||
|
|
||||||
all_ok
|
all_ok
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user