Compare commits

...

10 Commits

Author SHA1 Message Date
spinline
795eef4bda fix: refine push error matching and maximize webhook logging for debugging
All checks were successful
Build MIPS Binary / build (push) Successful in 1m50s
2026-02-13 12:51:46 +03:00
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
spinline
3bb2d68a65 perf: increase background polling interval to 60 seconds
All checks were successful
Build MIPS Binary / build (push) Successful in 1m51s
2026-02-13 12:26:09 +03:00
spinline
fe117cdaec chore: add detailed logging for web push notifications in webhook handler
All checks were successful
Build MIPS Binary / build (push) Successful in 1m50s
2026-02-13 12:11:14 +03:00
spinline
e062a3c8cd feat: add internal notification endpoint for rTorrent event hooks
All checks were successful
Build MIPS Binary / build (push) Successful in 1m51s
2026-02-13 12:08:40 +03:00
spinline
ae2c9c934d fix: center toast notifications on mobile screens
All checks were successful
Build MIPS Binary / build (push) Successful in 1m54s
2026-02-13 00:08:54 +03:00
spinline
f7e1356eae fix: restrict Add Torrent dialog width for better UI
All checks were successful
Build MIPS Binary / build (push) Successful in 1m50s
2026-02-13 00:06:40 +03:00
6 changed files with 82 additions and 4 deletions

View File

@@ -7,6 +7,7 @@ use rust_embed::RustEmbed;
pub mod auth;
pub mod setup;
pub mod notifications;
#[derive(RustEmbed)]
#[folder = "../frontend/dist"]

View File

@@ -0,0 +1,54 @@
use axum::{
extract::{State, Query},
http::StatusCode,
};
use serde::Deserialize;
use shared::{AppEvent, SystemNotification, NotificationLevel};
use crate::AppState;
#[derive(Deserialize)]
pub struct TorrentFinishedQuery {
pub name: String,
pub hash: String,
}
pub async fn torrent_finished_handler(
State(state): State<AppState>,
Query(params): Query<TorrentFinishedQuery>,
) -> StatusCode {
tracing::info!("WEBHOOK: Received notification from rTorrent. Name: {:?}, Hash: {:?}", params.name, params.hash);
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 {
level: NotificationLevel::Success,
message: message.clone(),
};
let _ = state.event_bus.send(AppEvent::Notification(notification));
// 2. Send Web Push Notification (for Background)
#[cfg(feature = "push-notifications")]
{
let push_store = state.push_store.clone();
let title = "Torrent Tamamlandı".to_string();
let body = message;
let name_for_log = torrent_name.clone();
tokio::spawn(async move {
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 task completed for: {}", name_for_log),
Err(e) => tracing::error!("Failed to send Web Push notification for {}: {:?}", name_for_log, e),
}
});
}
StatusCode::OK
}

View File

@@ -60,6 +60,7 @@ async fn auth_middleware(
|| path.starts_with("/api/server_fns/get_setup_status")
|| path.starts_with("/api/server_fns/Setup")
|| path.starts_with("/api/server_fns/setup")
|| path.starts_with("/api/internal/")
|| path.starts_with("/swagger-ui")
|| path.starts_with("/api-docs")
|| !path.starts_with("/api/")
@@ -313,7 +314,7 @@ async fn main() {
let loop_interval = if active_clients > 0 {
Duration::from_secs(1)
} else {
Duration::from_secs(30)
Duration::from_secs(60)
};
// 1. Fetch Torrents
@@ -434,6 +435,7 @@ async fn main() {
let db_for_ctx = db.clone();
let app = app
.route("/api/events", get(sse::sse_handler))
.route("/api/internal/torrent-finished", post(handlers::notifications::torrent_finished_handler))
.route("/api/server_fns/{*fn_name}", post({
let scgi_path = scgi_path_for_ctx.clone();
let db = db_for_ctx.clone();

View File

@@ -192,10 +192,30 @@ 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_debug = format!("{:?}", e);
let err_display = format!("{}", e);
tracing::error!("Failed to build push message for {}: (Debug: {}) (Display: {})", subscription.endpoint, err_debug, err_display);
// Broaden error matching to catch various encryption and auth failures
let is_critical_error = err_debug.to_lowercase().contains("encrypt")
|| err_debug.to_lowercase().contains("vapid")
|| err_debug.to_lowercase().contains("unauthorized")
|| err_debug.to_lowercase().contains("unknown error");
if is_critical_error {
tracing::warn!("Critical push error detected, removing invalid subscription: {}", subscription.endpoint);
let _ = store.remove_subscription(&subscription.endpoint).await;
}
}
}
}
Err(e) => tracing::error!("Failed to build VAPID signature: {}", e),

View File

@@ -41,7 +41,7 @@ pub fn Toolbar() -> impl IntoView {
<span class="hidden sm:inline">"Add Torrent"</span>
<span class="sm:hidden">"Add"</span>
</DialogTrigger>
<DialogContent id="add-torrent-dialog">
<DialogContent id="add-torrent-dialog" class="sm:max-w-[425px]">
<AddTorrentDialogContent />
</DialogContent>
</Dialog>

View File

@@ -170,9 +170,10 @@ pub fn Toaster(#[prop(default = SonnerPosition::default())] position: SonnerPosi
<div
class=tw_merge!(
"fixed z-[100] flex gap-3 pointer-events-none w-full sm:w-[400px]",
"left-1/2 -translate-x-1/2 sm:left-auto sm:translate-x-0 px-4 sm:px-0", // Mobile centering fix
if is_bottom { "flex-col-reverse" } else { "flex-col" },
container_class,
"pb-[env(safe-area-inset-bottom)] pt-[env(safe-area-inset-top)] px-4 sm:px-0"
"pb-[env(safe-area-inset-bottom)] pt-[env(safe-area-inset-top)]"
)
>
<For