aboutsummaryrefslogtreecommitdiff
path: root/aero-proto/src/dav
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2024-05-27 08:03:21 +0200
committerQuentin Dufour <quentin@deuxfleurs.fr>2024-05-27 08:03:21 +0200
commit418adf92be86ea83008a145180837f1e0ad3018a (patch)
tree5e3e9c0efea5c11577ebeaaa9e221b20c43ebb7c /aero-proto/src/dav
parent68e08bed4f8f589d2e45bcd82a99090032a56b95 (diff)
downloadaerogramme-418adf92be86ea83008a145180837f1e0ad3018a.tar.gz
aerogramme-418adf92be86ea83008a145180837f1e0ad3018a.zip
debug support of calendar-data pruning
Diffstat (limited to 'aero-proto/src/dav')
-rw-r--r--aero-proto/src/dav/controller.rs1
-rw-r--r--aero-proto/src/dav/resource.rs53
2 files changed, 43 insertions, 11 deletions
diff --git a/aero-proto/src/dav/controller.rs b/aero-proto/src/dav/controller.rs
index abf6a97..eeb6d43 100644
--- a/aero-proto/src/dav/controller.rs
+++ b/aero-proto/src/dav/controller.rs
@@ -333,7 +333,6 @@ impl<'a> Path<'a> {
}
}
-//@FIXME move somewhere else
//@FIXME naive implementation, must be refactored later
use futures::stream::Stream;
fn apply_filter<'a>(
diff --git a/aero-proto/src/dav/resource.rs b/aero-proto/src/dav/resource.rs
index d65ce38..04bae4f 100644
--- a/aero-proto/src/dav/resource.rs
+++ b/aero-proto/src/dav/resource.rs
@@ -565,17 +565,49 @@ impl DavNode for EventNode {
dav::Property::GetEtag(etag)
}
dav::PropertyRequest::Extension(all::PropertyRequest::Cal(
- cal::PropertyRequest::CalendarData(_req),
- )) => {
+ cal::PropertyRequest::CalendarData(req),
+ )) => {
let ics = String::from_utf8(
this.col.get(this.blob_id).await.or(Err(n.clone()))?,
- )
- .or(Err(n.clone()))?;
+ )
+ .or(Err(n.clone()))?;
+
+ let new_ics = match &req.comp {
+ None => ics,
+ Some(prune_comp) => {
+ // parse content
+ let ics = match icalendar::parser::read_calendar(&ics) {
+ Ok(v) => v,
+ Err(e) => {
+ tracing::warn!(err=?e, "Unable to parse ICS in calendar-query");
+ return Err(n.clone())
+ }
+ };
+
+ // build a fake vcal component for caldav compat
+ let fake_vcal_component = icalendar::parser::Component {
+ name: cal::Component::VCalendar.as_str().into(),
+ properties: ics.properties,
+ components: ics.components,
+ };
+
+ // rebuild component
+ let new_comp = match aero_ical::prune::component(&fake_vcal_component, prune_comp) {
+ Some(v) => v,
+ None => return Err(n.clone()),
+ };
+
+ // reserialize
+ format!("{}", icalendar::parser::Calendar { properties: new_comp.properties, components: new_comp.components })
+ },
+ };
+
+
dav::Property::Extension(all::Property::Cal(
cal::Property::CalendarData(cal::CalendarDataPayload {
mime: None,
- payload: ics,
+ payload: new_ics,
}),
))
}
@@ -634,14 +666,15 @@ impl DavNode for EventNode {
// so we load everything in memory
let calendar = self.col.clone();
let blob_id = self.blob_id.clone();
- let r = async move {
- let content = calendar
+ let calblob = async move {
+ let raw_ics = calendar
.get(blob_id)
.await
- .or(Err(std::io::Error::from(std::io::ErrorKind::Interrupted)));
- Ok(hyper::body::Bytes::from(content?))
+ .or(Err(std::io::Error::from(std::io::ErrorKind::Interrupted)))?;
+
+ Ok(hyper::body::Bytes::from(raw_ics))
};
- futures::stream::once(Box::pin(r)).boxed()
+ futures::stream::once(Box::pin(calblob)).boxed()
}
fn content_type(&self) -> &str {