Send ntfy notifications
This commit is contained in:
parent
77a72329a8
commit
bdcc0def42
10 changed files with 289 additions and 44 deletions
47
src/main.rs
47
src/main.rs
|
|
@ -5,6 +5,8 @@ use crate::args::Args;
|
|||
use crate::config::{get_db_path, load_config};
|
||||
use crate::db::Database;
|
||||
use crate::magnet::{extract_magnet_links, Magnet};
|
||||
use crate::notifications::notification::Notification;
|
||||
use crate::notifications::ntfy::NtfyNotification;
|
||||
use chrono::{DateTime, Utc};
|
||||
use clap::Parser;
|
||||
use color_eyre::eyre::{eyre, Result, WrapErr};
|
||||
|
|
@ -21,6 +23,7 @@ mod config;
|
|||
mod db;
|
||||
mod magnet;
|
||||
mod models;
|
||||
mod notifications;
|
||||
mod reddit_client;
|
||||
mod report;
|
||||
mod schema;
|
||||
|
|
@ -172,6 +175,28 @@ async fn main() -> Result<()> {
|
|||
debug!("No Transmission configuration found");
|
||||
}
|
||||
|
||||
// Initialize notifications
|
||||
let mut notifications: Vec<Box<dyn Notification>> = Vec::new();
|
||||
|
||||
// Add Ntfy notification if enabled
|
||||
if let Some(ntfy_config) = conf.ntfy {
|
||||
if ntfy_config.enable {
|
||||
info!("Initializing Ntfy notification");
|
||||
match NtfyNotification::new(ntfy_config) {
|
||||
Ok(ntfy_notification) => {
|
||||
notifications.push(Box::new(ntfy_notification));
|
||||
}
|
||||
Err(e) => {
|
||||
warn!("Failed to initialize Ntfy notification: {}", e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
debug!("Ntfy notification is disabled");
|
||||
}
|
||||
} else {
|
||||
debug!("No Ntfy configuration found");
|
||||
}
|
||||
|
||||
// Process all actions and collect results
|
||||
let mut action_results = HashMap::new();
|
||||
|
||||
|
|
@ -194,7 +219,27 @@ async fn main() -> Result<()> {
|
|||
}
|
||||
}
|
||||
|
||||
for line in report::generate_report(&action_results, total_new_links).lines() {
|
||||
// Send notifications
|
||||
for notification in ¬ifications {
|
||||
match notification
|
||||
.send_notification(&action_results, total_new_links)
|
||||
.await
|
||||
{
|
||||
Ok(_) => {
|
||||
debug!("Successfully sent notification to {}", notification.name());
|
||||
}
|
||||
Err(e) => {
|
||||
warn!(
|
||||
"Failed to send notification to {}: {}",
|
||||
notification.name(),
|
||||
e
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Generate and display report
|
||||
for line in report::generate_report(&action_results, total_new_links, true).lines() {
|
||||
info!("{}", line);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue