Compare commits

...

4 Commits

Author SHA1 Message Date
spinline
3ad8424d17 fix: resolve borrow-after-move error in notification handler
All checks were successful
Build MIPS Binary / build (push) Successful in 1m54s
2026-02-13 12:44:55 +03:00
spinline
83feb5a5cf fix: broaden push notification error handling to clear invalid subscriptions more effectively
Some checks failed
Build MIPS Binary / build (push) Failing after 1m5s
2026-02-13 12:41:11 +03:00
spinline
0dd97f3d7e chore: improve webhook logging for better debugging
Some checks failed
Build MIPS Binary / build (push) Failing after 1m5s
2026-02-13 12:38:29 +03:00
spinline
bb32c1f7f6 fix: improve push notification reliability by removing invalid subscriptions and update rTorrent webhook logging
All checks were successful
Build MIPS Binary / build (push) Successful in 1m50s
2026-02-13 12:31:06 +03:00
2 changed files with 26 additions and 7 deletions

View File

@@ -16,9 +16,15 @@ pub async fn torrent_finished_handler(
State(state): State<AppState>,
Query(params): Query<TorrentFinishedQuery>,
) -> StatusCode {
tracing::info!("Torrent finished notification received: {} ({})", params.name, params.hash);
tracing::info!("WEBHOOK: Received notification from rTorrent. Name: {:?}, Hash: {:?}", params.name, params.hash);
let message = format!("Torrent tamamlandı: {}", params.name);
let torrent_name = if params.name.is_empty() || params.name == "$d.name=" {
"Bilinmeyen Torrent".to_string()
} else {
params.name.clone()
};
let message = format!("Torrent tamamlandı: {}", torrent_name);
// 1. Send to active SSE clients (for Toast)
let notification = SystemNotification {
@@ -33,13 +39,13 @@ pub async fn torrent_finished_handler(
let push_store = state.push_store.clone();
let title = "Torrent Tamamlandı".to_string();
let body = message;
let torrent_name = params.name.clone();
let name_for_log = torrent_name.clone();
tokio::spawn(async move {
tracing::info!("Attempting to send Web Push notification for torrent: {}", torrent_name);
tracing::info!("Attempting to send Web Push notification for torrent: {}", name_for_log);
match crate::push::send_push_notification(&push_store, &title, &body).await {
Ok(_) => tracing::info!("Web Push notification sent successfully for: {}", torrent_name),
Err(e) => tracing::error!("Failed to send Web Push notification for {}: {:?}", torrent_name, e),
Ok(_) => tracing::info!("Web Push notification task completed for: {}", name_for_log),
Err(e) => tracing::error!("Failed to send Web Push notification for {}: {:?}", name_for_log, e),
}
});
}

View File

@@ -192,10 +192,23 @@ pub async fn send_push_notification(
}
Err(e) => {
tracing::error!("Failed to send push notification to {}: {}", subscription.endpoint, e);
// If subscription is invalid/expired (Gone or Unauthorized), remove it
if format!("{:?}", e).contains("Unauthorized") || format!("{:?}", e).contains("Gone") {
tracing::info!("Removing invalid subscription: {}", subscription.endpoint);
let _ = store.remove_subscription(&subscription.endpoint).await;
}
}
}
}
Err(e) => tracing::error!("Failed to build push message: {}", e),
Err(e) => {
let err_msg = format!("{:?}", e);
tracing::error!("Failed to build push message for {}: {}", subscription.endpoint, err_msg);
// Broaden error matching to catch various encryption and auth failures
if err_msg.contains("encrypting") || err_msg.contains("Vapid") || err_msg.contains("Unauthorized") {
tracing::warn!("Critical push error for subscriber {}, removing invalid subscription", subscription.endpoint);
let _ = store.remove_subscription(&subscription.endpoint).await;
}
}
}
}
Err(e) => tracing::error!("Failed to build VAPID signature: {}", e),