|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
#[macro_use] |
|
|
|
|
extern crate diesel; |
|
|
|
|
|
|
|
|
|
use std::mem::replace; |
|
|
|
|
use std::io::Read; |
|
|
|
|
use std::fs::read_to_string; |
|
|
|
|
use std::sync::RwLock; |
|
|
|
@ -18,6 +19,16 @@ use model::{Calendar, NewCalendar, Event};
|
|
|
|
|
mod ics; |
|
|
|
|
use ics::{Parser, Object, GetValue}; |
|
|
|
|
|
|
|
|
|
fn extract_vevent_objs(results: &mut Vec<Object>, mut obj: Object) { |
|
|
|
|
let children = replace(&mut obj.children, vec![]); |
|
|
|
|
if obj.name == "VEVENT" { |
|
|
|
|
results.push(obj); |
|
|
|
|
} |
|
|
|
|
for child in children.into_iter() { |
|
|
|
|
extract_vevent_objs(results, *child); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn obj_to_event(calendar: String, obj: Object) -> Option<Event> { |
|
|
|
|
if obj.name != "VEVENT" { |
|
|
|
|
return None; |
|
|
|
@ -141,11 +152,15 @@ impl Resources {
|
|
|
|
|
len if len > 0 => { |
|
|
|
|
let data = &buf[..len]; |
|
|
|
|
p.feed(data, |obj| { |
|
|
|
|
let dbg = format!("{:?}", obj); |
|
|
|
|
if let Some(event) = obj_to_event(cal_opts.url.clone(), obj) { |
|
|
|
|
events.push(event); |
|
|
|
|
} else { |
|
|
|
|
println!("ignore {}", dbg); |
|
|
|
|
let mut objs = vec![]; |
|
|
|
|
extract_vevent_objs(&mut objs, obj); |
|
|
|
|
for obj in objs { |
|
|
|
|
let dbg = format!("{:?}", obj); |
|
|
|
|
if let Some(event) = obj_to_event(cal_opts.url.clone(), obj) { |
|
|
|
|
events.push(event); |
|
|
|
|
} else { |
|
|
|
|
println!("ignore {}", dbg); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|