store(Event): Keep plaintext ics string

This commit is contained in:
Lennart
2024-05-25 17:39:10 +02:00
parent be27d4d7fa
commit 35acfe1575

View File

@@ -1,7 +1,6 @@
use crate::timestamps::{parse_datetime, parse_duration}; use crate::timestamps::{parse_datetime, parse_duration};
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use chrono::{Duration, NaiveDateTime, Timelike}; use chrono::{Duration, NaiveDateTime, Timelike};
use ical::generator::Emitter;
use ical::parser::{ical::component::IcalCalendar, Component}; use ical::parser::{ical::component::IcalCalendar, Component};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256}; use sha2::{Digest, Sha256};
@@ -10,6 +9,7 @@ use std::io::BufReader;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Event { pub struct Event {
uid: String, uid: String,
ics: String,
cal: IcalCalendar, cal: IcalCalendar,
} }
@@ -60,7 +60,7 @@ impl Event {
if cal.events.len() != 1 { if cal.events.len() != 1 {
return Err(anyhow!("multiple or no events")); return Err(anyhow!("multiple or no events"));
} }
let event = Self { uid, cal }; let event = Self { uid, cal, ics };
// Run getters now to validate the input and ensure that they'll work later on // Run getters now to validate the input and ensure that they'll work later on
event.get_first_occurence()?; event.get_first_occurence()?;
event.get_last_occurence()?; event.get_last_occurence()?;
@@ -76,8 +76,8 @@ impl Event {
format!("{:x}", hasher.finalize()) format!("{:x}", hasher.finalize())
} }
pub fn get_ics(&self) -> String { pub fn get_ics(&self) -> &str {
self.cal.generate() &self.ics
} }
pub fn get_first_occurence(&self) -> Result<NaiveDateTime> { pub fn get_first_occurence(&self) -> Result<NaiveDateTime> {