Refactoring: Lots of fixes still necessary to get it into a working state

This commit is contained in:
Lennart
2024-05-25 22:00:09 +02:00
parent 35acfe1575
commit 7a0a91f823
14 changed files with 470 additions and 223 deletions

View File

@@ -2,8 +2,9 @@ use actix_web::HttpRequest;
use anyhow::Result;
use async_trait::async_trait;
use rustical_auth::AuthInfo;
use rustical_dav::dav_resource::{Resource, ResourceService};
use rustical_dav::error::Error;
use rustical_dav::{resource::Resource, xml_snippets::HrefElement};
use rustical_dav::xml_snippets::HrefElement;
use serde::Serialize;
use strum::{EnumString, IntoStaticStr, VariantNames};
@@ -33,34 +34,16 @@ pub enum RootPropResponse {
CurrentUserPrincipal(HrefElement),
}
#[async_trait(?Send)]
impl Resource for RootResource {
type UriComponents = ();
type MemberType = Self;
pub struct RootFile {
pub prefix: String,
pub principal: String,
pub path: String,
}
impl Resource for RootFile {
type PropType = RootProp;
type PropResponse = RootPropResponse;
fn get_path(&self) -> &str {
&self.path
}
async fn get_members(&self) -> Result<Vec<Self::MemberType>> {
Ok(vec![])
}
async fn acquire_from_request(
req: HttpRequest,
auth_info: AuthInfo,
_uri_components: Self::UriComponents,
prefix: String,
) -> Result<Self, Error> {
Ok(Self {
prefix,
principal: auth_info.user_id,
path: req.path().to_string(),
})
}
fn get_prop(&self, prop: Self::PropType) -> Result<Self::PropResponse> {
match prop {
RootProp::Resourcetype => Ok(RootPropResponse::Resourcetype(Resourcetype::default())),
@@ -69,4 +52,44 @@ impl Resource for RootResource {
)),
}
}
fn get_path(&self) -> &str {
&self.path
}
}
#[async_trait(?Send)]
impl ResourceService for RootResource {
type PathComponents = ();
type MemberType = RootFile;
type File = RootFile;
async fn get_members(
&self,
_auth_info: AuthInfo,
_path_components: Self::PathComponents,
) -> Result<Vec<Self::MemberType>> {
Ok(vec![])
}
async fn new(
req: HttpRequest,
auth_info: AuthInfo,
_path_components: Self::PathComponents,
prefix: String,
) -> Result<Self, Error> {
Ok(Self {
prefix,
principal: auth_info.user_id,
path: req.path().to_string(),
})
}
async fn get_file(&self) -> Result<Self::File> {
Ok(RootFile {
path: self.path.to_owned(),
principal: self.principal.to_owned(),
prefix: self.prefix.to_owned(),
})
}
}