feat: add internal notification endpoint for rTorrent event hooks
All checks were successful
Build MIPS Binary / build (push) Successful in 1m51s

This commit is contained in:
spinline
2026-02-13 12:08:40 +03:00
parent ae2c9c934d
commit e062a3c8cd
3 changed files with 47 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
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!("Torrent finished notification received: {} ({})", params.name, params.hash);
let message = format!("Torrent tamamlandı: {}", params.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;
tokio::spawn(async move {
if let Err(e) = crate::push::send_push_notification(&push_store, &title, &body).await {
tracing::error!("Failed to send push notification from webhook: {}", e);
}
});
}
StatusCode::OK
}