diff --git a/notifico-core/src/simpletransport.rs b/notifico-core/src/simpletransport.rs index d5ec07e..19717bb 100644 --- a/notifico-core/src/simpletransport.rs +++ b/notifico-core/src/simpletransport.rs @@ -89,7 +89,7 @@ impl EnginePlugin for SimpleTransportWrapper { }; for contact in contacts { - if !self.inner.supports_contact(&contact.r#type) { + if self.inner.has_contacts() && !self.inner.supports_contact(&contact.r#type) { continue; } for message in &context.messages.clone() { diff --git a/transports/notifico-gotify/src/credentials.rs b/transports/notifico-gotify/src/credentials.rs index 0f8084d..a654e61 100644 --- a/transports/notifico-gotify/src/credentials.rs +++ b/transports/notifico-gotify/src/credentials.rs @@ -1,20 +1,33 @@ use notifico_core::credentials::{RawCredential, TypedCredential}; use notifico_core::error::EngineError; use serde::{Deserialize, Serialize}; +use std::borrow::Cow; +use std::collections::BTreeMap; use url::Url; #[derive(Serialize, Deserialize)] pub struct GotifyCredentials { - pub url: Url, + pub base_url: Url, + pub token: String, } impl TryFrom for GotifyCredentials { type Error = EngineError; fn try_from(value: RawCredential) -> Result { - let url = Url::parse(&value.value).map_err(|_| EngineError::InvalidCredentialFormat)?; + let base_url = + Url::parse(&value.value).map_err(|_| EngineError::InvalidCredentialFormat)?; - Ok(Self { url }) + let query: BTreeMap, Cow> = base_url.query_pairs().into_iter().collect(); + let token = query + .get("token") + .ok_or(EngineError::InvalidCredentialFormat)? + .to_string(); + + let base_url = + Url::parse(&format!("{}://{}", base_url.scheme(), base_url.authority())).unwrap(); + + Ok(Self { base_url, token }) } } diff --git a/transports/notifico-gotify/src/lib.rs b/transports/notifico-gotify/src/lib.rs index b3af031..83b29dd 100644 --- a/transports/notifico-gotify/src/lib.rs +++ b/transports/notifico-gotify/src/lib.rs @@ -49,8 +49,12 @@ impl SimpleTransport for GotifyTransport { extras: None, }; + let url = format!("{}message?token={}", credential.base_url, credential.token); + + println!("Sending message to Gotify: {}", url); + self.client - .post(credential.url.clone()) + .post(url) .json(&request) .send() .await