Skip to content

Commit

Permalink
Fix gotify integration
Browse files Browse the repository at this point in the history
  • Loading branch information
GamePad64 committed Dec 15, 2024
1 parent 5af595c commit 3ebf1d1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion notifico-core/src/simpletransport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
19 changes: 16 additions & 3 deletions transports/notifico-gotify/src/credentials.rs
Original file line number Diff line number Diff line change
@@ -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<RawCredential> for GotifyCredentials {
type Error = EngineError;

fn try_from(value: RawCredential) -> Result<Self, Self::Error> {
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<str>, Cow<str>> = 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 })
}
}

Expand Down
6 changes: 5 additions & 1 deletion transports/notifico-gotify/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3ebf1d1

Please sign in to comment.