diff options
Diffstat (limited to 'aero-proto/src/dav/node.rs')
-rw-r--r-- | aero-proto/src/dav/node.rs | 68 |
1 files changed, 43 insertions, 25 deletions
diff --git a/aero-proto/src/dav/node.rs b/aero-proto/src/dav/node.rs index d246280..877342a 100644 --- a/aero-proto/src/dav/node.rs +++ b/aero-proto/src/dav/node.rs @@ -1,16 +1,17 @@ use anyhow::Result; -use futures::stream::{BoxStream, StreamExt}; use futures::future::{BoxFuture, FutureExt}; +use futures::stream::{BoxStream, StreamExt}; use hyper::body::Bytes; -use aero_dav::types as dav; -use aero_dav::realization::All; use aero_collections::davdag::Etag; +use aero_dav::realization::All; +use aero_dav::types as dav; use super::controller::ArcUser; pub(crate) type Content<'a> = BoxStream<'a, std::result::Result<Bytes, std::io::Error>>; -pub(crate) type PropertyStream<'a> = BoxStream<'a, std::result::Result<dav::Property<All>, dav::PropertyRequest<All>>>; +pub(crate) type PropertyStream<'a> = + BoxStream<'a, std::result::Result<dav::Property<All>, dav::PropertyRequest<All>>>; pub(crate) enum PutPolicy { OverwriteAll, @@ -25,7 +26,12 @@ pub(crate) trait DavNode: Send { /// This node direct children fn children<'a>(&self, user: &'a ArcUser) -> BoxFuture<'a, Vec<Box<dyn DavNode>>>; /// Recursively fetch a child (progress inside the filesystem hierarchy) - fn fetch<'a>(&self, user: &'a ArcUser, path: &'a [&str], create: bool) -> BoxFuture<'a, Result<Box<dyn DavNode>>>; + fn fetch<'a>( + &self, + user: &'a ArcUser, + path: &'a [&str], + create: bool, + ) -> BoxFuture<'a, Result<Box<dyn DavNode>>>; // node properties /// Get the path @@ -36,13 +42,17 @@ pub(crate) trait DavNode: Send { fn properties(&self, user: &ArcUser, prop: dav::PropName<All>) -> PropertyStream<'static>; //fn properties(&self, user: &ArcUser, prop: dav::PropName<All>) -> Vec<dav::AnyProperty<All>>; /// Put an element (create or update) - fn put<'a>(&'a self, policy: PutPolicy, stream: Content<'a>) -> BoxFuture<'a, std::result::Result<Etag, std::io::Error>>; + fn put<'a>( + &'a self, + policy: PutPolicy, + stream: Content<'a>, + ) -> BoxFuture<'a, std::result::Result<Etag, std::io::Error>>; /// Content type of the element fn content_type(&self) -> &str; /// Get ETag fn etag(&self) -> BoxFuture<Option<Etag>>; /// Get content - fn content(&self) -> Content<'static>; + fn content<'a>(&self) -> Content<'a>; /// Delete fn delete(&self) -> BoxFuture<std::result::Result<(), std::io::Error>>; @@ -52,24 +62,32 @@ pub(crate) trait DavNode: Send { fn response_propname(&self, user: &ArcUser) -> dav::Response<All> { dav::Response { status_or_propstat: dav::StatusOrPropstat::PropStat( - dav::Href(self.path(user)), - vec![ - dav::PropStat { - status: dav::Status(hyper::StatusCode::OK), - prop: dav::AnyProp(self.supported_properties(user).0.into_iter().map(dav::AnyProperty::Request).collect()), - error: None, - responsedescription: None, - } - ], + dav::Href(self.path(user)), + vec![dav::PropStat { + status: dav::Status(hyper::StatusCode::OK), + prop: dav::AnyProp( + self.supported_properties(user) + .0 + .into_iter() + .map(dav::AnyProperty::Request) + .collect(), + ), + error: None, + responsedescription: None, + }], ), error: None, location: None, - responsedescription: None + responsedescription: None, } } /// Utility function to get a prop response from a node & a list of propname - fn response_props(&self, user: &ArcUser, props: dav::PropName<All>) -> BoxFuture<'static, dav::Response<All>> { + fn response_props( + &self, + user: &ArcUser, + props: dav::PropName<All>, + ) -> BoxFuture<'static, dav::Response<All>> { //@FIXME we should make the DAV parsed object a stream... let mut result_stream = self.properties(user, props); let path = self.path(user); @@ -87,8 +105,8 @@ pub(crate) trait DavNode: Send { // If at least one property has been found on this object, adding a HTTP 200 propstat to // the response if !found.is_empty() { - prop_desc.push(dav::PropStat { - status: dav::Status(hyper::StatusCode::OK), + prop_desc.push(dav::PropStat { + status: dav::Status(hyper::StatusCode::OK), prop: dav::AnyProp(found), error: None, responsedescription: None, @@ -98,8 +116,8 @@ pub(crate) trait DavNode: Send { // If at least one property can't be found on this object, adding a HTTP 404 propstat to // the response if !not_found.is_empty() { - prop_desc.push(dav::PropStat { - status: dav::Status(hyper::StatusCode::NOT_FOUND), + prop_desc.push(dav::PropStat { + status: dav::Status(hyper::StatusCode::NOT_FOUND), prop: dav::AnyProp(not_found), error: None, responsedescription: None, @@ -111,9 +129,9 @@ pub(crate) trait DavNode: Send { status_or_propstat: dav::StatusOrPropstat::PropStat(dav::Href(path), prop_desc), error: None, location: None, - responsedescription: None + responsedescription: None, } - }.boxed() + } + .boxed() } } - |