Change how CalDAV/CardDAV services are initialised

This commit is contained in:
Lennart
2025-01-26 14:13:56 +01:00
parent 33b7f748b8
commit 8fda600e7f
3 changed files with 68 additions and 77 deletions

View File

@@ -1,4 +1,4 @@
use actix_web::dev::ServiceResponse;
use actix_web::dev::{HttpServiceFactory, ServiceResponse};
use actix_web::http::header::{HeaderName, HeaderValue};
use actix_web::http::{Method, StatusCode};
use actix_web::middleware::{ErrorHandlerResponse, ErrorHandlers};
@@ -24,20 +24,19 @@ mod subscription;
pub use error::Error;
pub fn configure_dav<
pub fn caldav_service<
AP: AuthenticationProvider,
AS: AddressbookStore,
C: CalendarStore,
S: SubscriptionStore,
>(
cfg: &mut web::ServiceConfig,
auth_provider: Arc<AP>,
store: Arc<C>,
addr_store: Arc<AS>,
subscription_store: Arc<S>,
) {
) -> impl HttpServiceFactory {
let birthday_store = Arc::new(ContactBirthdayStore::new(addr_store));
cfg.service(
web::scope("")
.wrap(AuthenticationMiddleware::new(auth_provider))
.wrap(
@@ -93,6 +92,5 @@ pub fn configure_dav<
)
)
),
).service(subscription_resource::<S>()),
);
).service(subscription_resource::<S>())
}

View File

@@ -1,5 +1,5 @@
use actix_web::{
dev::ServiceResponse,
dev::{HttpServiceFactory, ServiceResponse},
http::{
header::{HeaderName, HeaderValue},
Method, StatusCode,
@@ -25,13 +25,11 @@ pub mod addressbook;
pub mod error;
pub mod principal;
pub fn configure_dav<AP: AuthenticationProvider, A: AddressbookStore, S: SubscriptionStore>(
cfg: &mut web::ServiceConfig,
pub fn carddav_service<AP: AuthenticationProvider, A: AddressbookStore, S: SubscriptionStore>(
auth_provider: Arc<AP>,
store: Arc<A>,
subscription_store: Arc<S>,
) {
cfg.service(
) -> impl HttpServiceFactory {
web::scope("")
.wrap(AuthenticationMiddleware::new(auth_provider))
.wrap(
@@ -79,6 +77,5 @@ pub fn configure_dav<AP: AuthenticationProvider, A: AddressbookStore, S: Subscri
),
),
),
),
);
)
}

View File

@@ -2,6 +2,8 @@ use actix_web::body::MessageBody;
use actix_web::dev::{ServiceFactory, ServiceRequest, ServiceResponse};
use actix_web::middleware::NormalizePath;
use actix_web::{web, App};
use rustical_caldav::caldav_service;
use rustical_carddav::carddav_service;
use rustical_frontend::{configure_frontend, FrontendConfig};
use rustical_store::auth::AuthenticationProvider;
use rustical_store::{AddressbookStore, CalendarStore, SubscriptionStore};
@@ -27,23 +29,17 @@ pub fn make_app<AS: AddressbookStore, CS: CalendarStore, S: SubscriptionStore>(
// .wrap(Logger::new("[%s] %r"))
.wrap(TracingLogger::default())
.wrap(NormalizePath::trim())
.service(web::scope("/caldav").configure(|cfg| {
rustical_caldav::configure_dav(
cfg,
.service(web::scope("/caldav").service(caldav_service(
auth_provider.clone(),
cal_store.clone(),
addr_store.clone(),
subscription_store.clone(),
)
}))
.service(web::scope("/carddav").configure(|cfg| {
rustical_carddav::configure_dav(
cfg,
)))
.service(web::scope("/carddav").service(carddav_service(
auth_provider.clone(),
addr_store.clone(),
subscription_store,
)
}))
)))
.service(
web::scope("/.well-known")
.service(web::redirect("/caldav", "/caldav"))