Simplify code

This commit is contained in:
FliegendeWurst 2020-05-12 15:09:32 +02:00
parent 5288d6723f
commit d815a6ea1e

View File

@ -727,37 +727,37 @@ use Object::*;
impl Object { impl Object {
fn name(&self) -> &str { fn name(&self) -> &str {
match self { match self {
Course { name, .. } => &name, Course { name, .. } |
Folder { name, .. } => &name, Folder { name, .. } |
File { name, .. } => &name, File { name, .. } |
Forum { name, .. } => &name, Forum { name, .. } |
Wiki { name, .. } |
Weblink { name, ..} |
Survey { name, .. } |
Presentation { name, .. } |
ExerciseHandler { name, .. } |
PluginDispatch { name, .. } |
Generic { name, .. } => &name,
Thread { url } => &url.thr_pk.as_ref().unwrap(), Thread { url } => &url.thr_pk.as_ref().unwrap(),
Wiki { name, .. } => &name,
Weblink { name, ..} => &name,
Survey { name, .. } => &name,
Presentation { name, .. } => &name,
ExerciseHandler { name, .. } => &name,
PluginDispatch { name, .. } => &name,
Video { url } => &url.url, Video { url } => &url.url,
Generic { name, .. } => &name,
} }
} }
fn url(&self) -> &URL { fn url(&self) -> &URL {
match self { match self {
Course { url, .. } => &url, Course { url, .. } |
Folder { url, .. } => &url, Folder { url, .. } |
File { url, .. } => &url, File { url, .. } |
Forum { url, .. } => &url, Forum { url, .. } |
Thread { url } => &url, Thread { url } |
Wiki { url, .. } => &url, Wiki { url, .. } |
Weblink { url, .. } => &url, Weblink { url, .. } |
Survey { url, .. } => &url, Survey { url, .. } |
Presentation { url, .. } => &url, Presentation { url, .. } |
ExerciseHandler { url, .. } => &url, ExerciseHandler { url, .. } |
PluginDispatch { url, .. } => &url, PluginDispatch { url, .. } |
Video { url } => &url, Video { url } |
Generic { url, .. } => &url, Generic { url, .. } => &url,
} }
} }
@ -808,20 +808,21 @@ impl Object {
} }
if url.url.starts_with("https://ilias.studium.kit.edu/goto.php") { if url.url.starts_with("https://ilias.studium.kit.edu/goto.php") {
if url.target.as_ref().map(|x| x.starts_with("wiki_")).unwrap_or(false) { let target = url.target.as_deref().unwrap_or("NONE");
if target.starts_with("wiki_") {
return Ok(Wiki { return Ok(Wiki {
name, name,
url // TODO: insert ref_id here url // TODO: insert ref_id here
}); });
} }
if url.target.as_ref().map(|x| x.starts_with("root_")).unwrap_or(false) { if target.starts_with("root_") {
// magazine link // magazine link
return Ok(Generic { return Ok(Generic {
name, name,
url url
}); });
} }
if url.target.as_ref().map(|x| x.starts_with("crs_")).unwrap_or(false) { if target.starts_with("crs_") {
let ref_id = url.target.as_ref().unwrap().split('_').nth(1).unwrap(); let ref_id = url.target.as_ref().unwrap().split('_').nth(1).unwrap();
url.ref_id = ref_id.to_owned(); url.ref_id = ref_id.to_owned();
return Ok(Course { return Ok(Course {
@ -829,7 +830,7 @@ impl Object {
url url
}); });
} }
if url.target.as_ref().map(|x| x.starts_with("frm_")).unwrap_or(false) { if target.starts_with("frm_") {
// TODO: extract post link? (this codepath should only be hit when parsing the content tree) // TODO: extract post link? (this codepath should only be hit when parsing the content tree)
let ref_id = url.target.as_ref().unwrap().split('_').nth(1).unwrap(); let ref_id = url.target.as_ref().unwrap().split('_').nth(1).unwrap();
url.ref_id = ref_id.to_owned(); url.ref_id = ref_id.to_owned();
@ -838,14 +839,14 @@ impl Object {
url url
}); });
} }
if url.target.as_ref().map(|x| x.starts_with("lm_")).unwrap_or(false) { if target.starts_with("lm_") {
// fancy interactive task // fancy interactive task
return Ok(Generic { return Ok(Presentation {
name, name,
url url
}); });
} }
if url.target.as_ref().map(|x| x.starts_with("fold_")).unwrap_or(false) { if target.starts_with("fold_") {
let ref_id = url.target.as_ref().unwrap().split('_').nth(1).unwrap(); let ref_id = url.target.as_ref().unwrap().split('_').nth(1).unwrap();
url.ref_id = ref_id.to_owned(); url.ref_id = ref_id.to_owned();
return Ok(Folder { return Ok(Folder {
@ -853,8 +854,7 @@ impl Object {
url url
}); });
} }
if url.target.as_ref().map(|x| x.starts_with("file_")).unwrap_or(false) { if target.starts_with("file_") {
let target = url.target.as_ref().ok_or(anyhow!("no download target"))?;
if !target.ends_with("download") { if !target.ends_with("download") {
// download page containing metadata // download page containing metadata
return Ok(Generic { return Ok(Generic {