mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 22:52:22 +00:00
Replacing garbage code with less garbage code :)
This commit is contained in:
@@ -15,7 +15,6 @@ use std::sync::Arc;
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
pub mod error;
|
||||
pub mod proptypes;
|
||||
pub mod resources;
|
||||
pub mod routes;
|
||||
pub mod tagname;
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
use std::io::Write;
|
||||
|
||||
use quick_xml::{events::BytesText, Writer};
|
||||
|
||||
pub fn write_string_prop<'a, W: Write>(
|
||||
writer: &'a mut Writer<W>,
|
||||
propname: &'a str,
|
||||
value: &str,
|
||||
) -> Result<&'a mut Writer<W>, quick_xml::Error> {
|
||||
let el = writer.create_element(propname);
|
||||
if value.is_empty() {
|
||||
el.write_empty()
|
||||
} else {
|
||||
el.write_text_content(BytesText::new(value))
|
||||
}
|
||||
}
|
||||
|
||||
pub fn write_href_prop<'a, W: Write>(
|
||||
writer: &'a mut Writer<W>,
|
||||
propname: &'a str,
|
||||
href: &str,
|
||||
) -> Result<&'a mut Writer<W>, quick_xml::Error> {
|
||||
write_hrefs_prop(writer, propname, vec![href])
|
||||
}
|
||||
|
||||
pub fn write_hrefs_prop<'a, W: Write>(
|
||||
writer: &'a mut Writer<W>,
|
||||
propname: &'a str,
|
||||
hrefs: Vec<&str>,
|
||||
) -> Result<&'a mut Writer<W>, quick_xml::Error> {
|
||||
writer
|
||||
.create_element(propname)
|
||||
.write_inner_content(|writer| {
|
||||
for href in hrefs {
|
||||
write_string_prop(writer, "href", href)?;
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
@@ -3,17 +3,17 @@ use std::{io::Write, sync::Arc};
|
||||
use actix_web::{web::Data, HttpRequest};
|
||||
use anyhow::{anyhow, Result};
|
||||
use async_trait::async_trait;
|
||||
use quick_xml::{events::BytesText, Writer};
|
||||
use quick_xml::Writer;
|
||||
use rustical_auth::AuthInfo;
|
||||
use rustical_store::calendar::{Calendar, CalendarStore};
|
||||
use strum::{EnumProperty, EnumString, IntoStaticStr, VariantNames};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
use crate::{
|
||||
proptypes::{write_href_prop, write_string_prop},
|
||||
tagname::TagName,
|
||||
use crate::tagname::TagName;
|
||||
use rustical_dav::{
|
||||
resource::Resource,
|
||||
xml_snippets::{write_resourcetype, HrefElement, TextElement},
|
||||
};
|
||||
use rustical_dav::{resource::Resource, xml_snippets::write_resourcetype};
|
||||
|
||||
pub struct CalendarResource<C: CalendarStore + ?Sized> {
|
||||
pub cal_store: Arc<RwLock<C>>,
|
||||
@@ -87,35 +87,22 @@ impl<C: CalendarStore + ?Sized> Resource for CalendarResource<C> {
|
||||
write_resourcetype(writer, vec!["C:calendar", "collection"])?
|
||||
}
|
||||
CalendarProp::CurrentUserPrincipal | CalendarProp::Owner => {
|
||||
write_href_prop(
|
||||
writer,
|
||||
writer.write_serializable(
|
||||
prop.tagname(),
|
||||
&format!("{}/{}/", self.prefix, self.principal),
|
||||
&HrefElement::new(format!("{}/{}/", self.prefix, self.principal)),
|
||||
)?;
|
||||
}
|
||||
CalendarProp::Displayname => {
|
||||
let el = writer.create_element(prop.tagname());
|
||||
if let Some(name) = self.calendar.clone().name {
|
||||
el.write_text_content(BytesText::new(&name))?;
|
||||
} else {
|
||||
el.write_empty()?;
|
||||
}
|
||||
let name = self.calendar.name.clone();
|
||||
writer.write_serializable(prop.tagname(), &TextElement(name))?;
|
||||
}
|
||||
CalendarProp::CalendarColor => {
|
||||
let el = writer.create_element(prop.tagname());
|
||||
if let Some(color) = self.calendar.clone().color {
|
||||
el.write_text_content(BytesText::new(&color))?;
|
||||
} else {
|
||||
el.write_empty()?;
|
||||
}
|
||||
let color = self.calendar.color.clone();
|
||||
writer.write_serializable(prop.tagname(), &TextElement(color))?;
|
||||
}
|
||||
CalendarProp::CalendarDescription => {
|
||||
let el = writer.create_element(prop.tagname());
|
||||
if let Some(description) = self.calendar.clone().description {
|
||||
el.write_text_content(BytesText::new(&description))?;
|
||||
} else {
|
||||
el.write_empty()?;
|
||||
}
|
||||
let description = self.calendar.description.clone();
|
||||
writer.write_serializable(prop.tagname(), &TextElement(description))?;
|
||||
}
|
||||
CalendarProp::SupportedCalendarComponentSet => {
|
||||
writer
|
||||
@@ -144,10 +131,16 @@ impl<C: CalendarStore + ?Sized> Resource for CalendarResource<C> {
|
||||
})?;
|
||||
}
|
||||
CalendarProp::Getcontenttype => {
|
||||
write_string_prop(writer, prop.tagname(), "text/calendar")?;
|
||||
writer.write_serializable(
|
||||
prop.tagname(),
|
||||
&TextElement(Some("text/calendar".to_owned())),
|
||||
)?;
|
||||
}
|
||||
CalendarProp::MaxResourceSize => {
|
||||
write_string_prop(writer, prop.tagname(), "10000000")?;
|
||||
writer.write_serializable(
|
||||
prop.tagname(),
|
||||
&TextElement(Some("10000000".to_owned())),
|
||||
)?;
|
||||
}
|
||||
CalendarProp::CurrentUserPrivilegeSet => {
|
||||
writer
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::{proptypes::write_string_prop, tagname::TagName};
|
||||
use crate::tagname::TagName;
|
||||
use actix_web::{web::Data, HttpRequest};
|
||||
use anyhow::{anyhow, Result};
|
||||
use async_trait::async_trait;
|
||||
use rustical_auth::AuthInfo;
|
||||
use rustical_dav::resource::Resource;
|
||||
use rustical_dav::{resource::Resource, xml_snippets::TextElement};
|
||||
use rustical_store::calendar::CalendarStore;
|
||||
use rustical_store::event::Event;
|
||||
use std::sync::Arc;
|
||||
@@ -69,13 +69,20 @@ impl<C: CalendarStore + ?Sized> Resource for EventResource<C> {
|
||||
) -> Result<()> {
|
||||
match prop {
|
||||
EventProp::Getetag => {
|
||||
write_string_prop(writer, prop.tagname(), &self.event.get_etag())?;
|
||||
writer.write_serializable(
|
||||
prop.tagname(),
|
||||
&TextElement(Some(self.event.get_etag())),
|
||||
)?;
|
||||
}
|
||||
EventProp::CalendarData => {
|
||||
write_string_prop(writer, prop.tagname(), &self.event.get_ics())?;
|
||||
writer
|
||||
.write_serializable(prop.tagname(), &TextElement(Some(self.event.get_ics())))?;
|
||||
}
|
||||
EventProp::Getcontenttype => {
|
||||
write_string_prop(writer, prop.tagname(), "text/calendar;charset=utf-8")?;
|
||||
writer.write_serializable(
|
||||
prop.tagname(),
|
||||
&TextElement(Some("text/calendar;charset=utf-8".to_owned())),
|
||||
)?;
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
use crate::{proptypes::write_href_prop, tagname::TagName};
|
||||
use crate::tagname::TagName;
|
||||
use actix_web::{web::Data, HttpRequest};
|
||||
use anyhow::{anyhow, Result};
|
||||
use async_trait::async_trait;
|
||||
use quick_xml::events::BytesText;
|
||||
use rustical_auth::AuthInfo;
|
||||
use rustical_dav::{resource::Resource, xml_snippets::write_resourcetype};
|
||||
use rustical_dav::{
|
||||
resource::Resource,
|
||||
xml_snippets::{write_resourcetype, HrefElement},
|
||||
};
|
||||
use rustical_store::calendar::CalendarStore;
|
||||
use std::sync::Arc;
|
||||
use strum::{EnumProperty, EnumString, IntoStaticStr, VariantNames};
|
||||
@@ -91,26 +93,15 @@ impl<C: CalendarStore + ?Sized> Resource for PrincipalCalendarsResource<C> {
|
||||
PrincipalProp::Resourcetype => {
|
||||
write_resourcetype(writer, vec!["principal", "collection"])?
|
||||
}
|
||||
PrincipalProp::CurrentUserPrincipal | PrincipalProp::PrincipalUrl => {
|
||||
write_href_prop(
|
||||
writer,
|
||||
prop.into(),
|
||||
&format!("{}/{}/", self.prefix, self.principal),
|
||||
PrincipalProp::CurrentUserPrincipal
|
||||
| PrincipalProp::PrincipalUrl
|
||||
| PrincipalProp::CalendarHomeSet
|
||||
| PrincipalProp::CalendarUserAddressSet => {
|
||||
writer.write_serializable(
|
||||
prop.tagname(),
|
||||
&HrefElement::new(format!("{}/{}/", self.prefix, self.principal)),
|
||||
)?;
|
||||
}
|
||||
PrincipalProp::CalendarHomeSet | PrincipalProp::CalendarUserAddressSet => {
|
||||
writer
|
||||
.create_element(prop.tagname())
|
||||
.write_inner_content(|writer| {
|
||||
writer
|
||||
.create_element("href")
|
||||
.write_text_content(BytesText::new(&format!(
|
||||
"{}/{}/",
|
||||
self.prefix, self.principal
|
||||
)))?;
|
||||
Ok::<(), quick_xml::Error>(())
|
||||
})?;
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user