cosmic_files/sequencing/
ntfy_notify.rs

1/// Push `pdf_bytes` to an ntfy topic as a PDF file attachment.
2///
3/// `topic` may be a bare topic name (sent to `https://ntfy.sh/{topic}`) or a full URL.
4pub async fn send_report_ntfy(
5    topic: &str,
6    pdf_bytes: Vec<u8>,
7    n_records: usize,
8) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
9    let url = if topic.starts_with("http://") || topic.starts_with("https://") {
10        topic.to_string()
11    } else {
12        format!("https://ntfy.sh/{topic}")
13    };
14
15    reqwest::Client::new()
16        .put(&url)
17        .header("Content-Type", "application/pdf")
18        .header("Filename", "ab1_susceptibility_report.pdf")
19        .header("Title", format!("AB1 scan complete ({n_records} records)"))
20        .body(pdf_bytes)
21        .send()
22        .await?
23        .error_for_status()?;
24
25    Ok(())
26}