mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 22:52:22 +00:00
Comment out broken DAV Push notifier
This commit is contained in:
@@ -23,4 +23,3 @@ reqwest.workspace = true
|
||||
tokio.workspace = true
|
||||
rustical_dav.workspace = true
|
||||
rustical_store.workspace = true
|
||||
web-push = { version = "0.11", default-features = false }
|
||||
|
||||
@@ -9,7 +9,7 @@ use rustical_xml::{XmlRootTag, XmlSerialize, XmlSerializeRoot};
|
||||
use std::{str::FromStr, sync::Arc};
|
||||
use tokio::sync::mpsc::Receiver;
|
||||
use tracing::{error, info, warn};
|
||||
use web_push::{SubscriptionInfo, WebPushMessage, WebPushMessageBuilder};
|
||||
// use web_push::{SubscriptionInfo, WebPushMessage, WebPushMessageBuilder};
|
||||
|
||||
#[derive(XmlSerialize, Debug)]
|
||||
struct PushMessageProp {
|
||||
@@ -30,39 +30,39 @@ struct PushMessage {
|
||||
propstat: PropstatElement<PushMessageProp>,
|
||||
}
|
||||
|
||||
pub fn build_request(message: WebPushMessage) -> Request {
|
||||
// A little janky :)
|
||||
let url = reqwest::Url::from_str(&message.endpoint.to_string()).unwrap();
|
||||
let mut builder = Request::new(Method::POST, url);
|
||||
|
||||
if let Some(topic) = message.topic {
|
||||
builder
|
||||
.headers_mut()
|
||||
.insert("Topic", HeaderValue::from_str(topic.as_str()).unwrap());
|
||||
}
|
||||
|
||||
if let Some(payload) = message.payload {
|
||||
builder.headers_mut().insert(
|
||||
header::CONTENT_ENCODING,
|
||||
HeaderValue::from_static(payload.content_encoding.to_str()),
|
||||
);
|
||||
builder.headers_mut().insert(
|
||||
header::CONTENT_TYPE,
|
||||
HeaderValue::from_static("application/octet-stream"),
|
||||
);
|
||||
|
||||
for (k, v) in payload.crypto_headers.into_iter() {
|
||||
let v: &str = v.as_ref();
|
||||
builder.headers_mut().insert(
|
||||
HeaderName::from_static(k),
|
||||
HeaderValue::from_str(&v).unwrap(),
|
||||
);
|
||||
}
|
||||
|
||||
*builder.body_mut() = Some(reqwest::Body::from(payload.content));
|
||||
}
|
||||
builder
|
||||
}
|
||||
// pub fn build_request(message: WebPushMessage) -> Request {
|
||||
// // A little janky :)
|
||||
// let url = reqwest::Url::from_str(&message.endpoint.to_string()).unwrap();
|
||||
// let mut builder = Request::new(Method::POST, url);
|
||||
//
|
||||
// if let Some(topic) = message.topic {
|
||||
// builder
|
||||
// .headers_mut()
|
||||
// .insert("Topic", HeaderValue::from_str(topic.as_str()).unwrap());
|
||||
// }
|
||||
//
|
||||
// if let Some(payload) = message.payload {
|
||||
// builder.headers_mut().insert(
|
||||
// header::CONTENT_ENCODING,
|
||||
// HeaderValue::from_static(payload.content_encoding.to_str()),
|
||||
// );
|
||||
// builder.headers_mut().insert(
|
||||
// header::CONTENT_TYPE,
|
||||
// HeaderValue::from_static("application/octet-stream"),
|
||||
// );
|
||||
//
|
||||
// for (k, v) in payload.crypto_headers.into_iter() {
|
||||
// let v: &str = v.as_ref();
|
||||
// builder.headers_mut().insert(
|
||||
// HeaderName::from_static(k),
|
||||
// HeaderValue::from_str(&v).unwrap(),
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// *builder.body_mut() = Some(reqwest::Body::from(payload.content));
|
||||
// }
|
||||
// builder
|
||||
// }
|
||||
|
||||
pub async fn push_notifier(
|
||||
allowed_push_servers: Option<Vec<String>>,
|
||||
@@ -102,46 +102,46 @@ pub async fn push_notifier(
|
||||
continue;
|
||||
}
|
||||
let payload = String::from_utf8(output).unwrap();
|
||||
for subscriber in subscribers {
|
||||
let push_resource = subscriber.push_resource;
|
||||
|
||||
let sub_info = SubscriptionInfo {
|
||||
endpoint: push_resource.to_owned(),
|
||||
keys: web_push::SubscriptionKeys {
|
||||
p256dh: subscriber.public_key,
|
||||
auth: subscriber.auth_secret,
|
||||
},
|
||||
};
|
||||
let mut builder = WebPushMessageBuilder::new(&sub_info);
|
||||
builder.set_payload(web_push::ContentEncoding::Aes128Gcm, payload.as_bytes());
|
||||
let push_message = builder.build().unwrap();
|
||||
let request = build_request(push_message);
|
||||
|
||||
let allowed = if let Some(allowed_push_servers) = &allowed_push_servers {
|
||||
if let Ok(resource_url) = reqwest::Url::parse(&push_resource) {
|
||||
let origin = resource_url.origin().ascii_serialization();
|
||||
allowed_push_servers
|
||||
.iter()
|
||||
.any(|allowed_push_server| allowed_push_server == &origin)
|
||||
} else {
|
||||
warn!("Invalid push url: {push_resource}");
|
||||
false
|
||||
}
|
||||
} else {
|
||||
true
|
||||
};
|
||||
|
||||
if allowed {
|
||||
info!("Sending a push message to {}: {}", push_resource, payload);
|
||||
if let Err(err) = client.execute(request).await {
|
||||
error!("{err}");
|
||||
}
|
||||
} else {
|
||||
warn!(
|
||||
"Not sending a push notification to {} since it's not allowed in dav_push::allowed_push_servers",
|
||||
push_resource
|
||||
);
|
||||
}
|
||||
}
|
||||
// for subscriber in subscribers {
|
||||
// let push_resource = subscriber.push_resource;
|
||||
//
|
||||
// let sub_info = SubscriptionInfo {
|
||||
// endpoint: push_resource.to_owned(),
|
||||
// keys: web_push::SubscriptionKeys {
|
||||
// p256dh: subscriber.public_key,
|
||||
// auth: subscriber.auth_secret,
|
||||
// },
|
||||
// };
|
||||
// let mut builder = WebPushMessageBuilder::new(&sub_info);
|
||||
// builder.set_payload(web_push::ContentEncoding::Aes128Gcm, payload.as_bytes());
|
||||
// let push_message = builder.build().unwrap();
|
||||
// let request = build_request(push_message);
|
||||
//
|
||||
// let allowed = if let Some(allowed_push_servers) = &allowed_push_servers {
|
||||
// if let Ok(resource_url) = reqwest::Url::parse(&push_resource) {
|
||||
// let origin = resource_url.origin().ascii_serialization();
|
||||
// allowed_push_servers
|
||||
// .iter()
|
||||
// .any(|allowed_push_server| allowed_push_server == &origin)
|
||||
// } else {
|
||||
// warn!("Invalid push url: {push_resource}");
|
||||
// false
|
||||
// }
|
||||
// } else {
|
||||
// true
|
||||
// };
|
||||
//
|
||||
// if allowed {
|
||||
// info!("Sending a push message to {}: {}", push_resource, payload);
|
||||
// if let Err(err) = client.execute(request).await {
|
||||
// error!("{err}");
|
||||
// }
|
||||
// } else {
|
||||
// warn!(
|
||||
// "Not sending a push notification to {} since it's not allowed in dav_push::allowed_push_servers",
|
||||
// push_resource
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user