mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 17:12:22 +00:00
Move DELETE method to Resource framework
This commit is contained in:
26
crates/dav/src/delete.rs
Normal file
26
crates/dav/src/delete.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
use crate::resource::ResourceService;
|
||||
use actix_web::web::Path;
|
||||
use actix_web::HttpRequest;
|
||||
use actix_web::HttpResponse;
|
||||
use actix_web::Responder;
|
||||
use rustical_auth::{AuthInfoExtractor, CheckAuthentication};
|
||||
|
||||
pub async fn route_delete<A: CheckAuthentication, R: ResourceService + ?Sized>(
|
||||
path_components: Path<R::PathComponents>,
|
||||
req: HttpRequest,
|
||||
auth: AuthInfoExtractor<A>,
|
||||
) -> Result<impl Responder, R::Error> {
|
||||
let auth_info = auth.inner;
|
||||
let path_components = path_components.into_inner();
|
||||
|
||||
let no_trash = req
|
||||
.headers()
|
||||
.get("X-No-Trashbin")
|
||||
.map(|val| matches!(val.to_str(), Ok("1")))
|
||||
.unwrap_or(false);
|
||||
|
||||
let resource_service = R::new(&req, &auth_info, path_components.clone()).await?;
|
||||
resource_service.delete_file(!no_trash).await?;
|
||||
|
||||
Ok(HttpResponse::Ok().body(""))
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
pub mod delete;
|
||||
pub mod depth_extractor;
|
||||
pub mod error;
|
||||
pub mod namespace;
|
||||
|
||||
@@ -51,8 +51,6 @@ pub trait ResourceService: Sized {
|
||||
path_components: Self::PathComponents,
|
||||
) -> Result<Self, Self::Error>;
|
||||
|
||||
async fn get_file(&self) -> Result<Self::File, Self::Error>;
|
||||
|
||||
async fn get_members(
|
||||
&self,
|
||||
_auth_info: AuthInfo,
|
||||
@@ -60,7 +58,11 @@ pub trait ResourceService: Sized {
|
||||
Ok(vec![])
|
||||
}
|
||||
|
||||
async fn get_file(&self) -> Result<Self::File, Self::Error>;
|
||||
async fn save_file(&self, file: Self::File) -> Result<(), Self::Error>;
|
||||
async fn delete_file(&self, _use_trashbin: bool) -> Result<(), Self::Error> {
|
||||
Err(crate::Error::Unauthorized.into())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
|
||||
Reference in New Issue
Block a user