Compare commits
4 Commits
release-20
...
release-20
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3ad8424d17 | ||
|
|
83feb5a5cf | ||
|
|
0dd97f3d7e | ||
|
|
bb32c1f7f6 |
@@ -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),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user