mirror of
https://github.com/FliegendeWurst/KIT-ILIAS-downloader.git
synced 2024-08-28 04:04:18 +00:00
Run cargo fmt
This commit is contained in:
parent
0396dfc096
commit
05abc5bdad
12
src/ilias.rs
12
src/ilias.rs
@ -10,7 +10,7 @@ use reqwest_cookie_store::CookieStoreMutex;
|
|||||||
use scraper::{ElementRef, Html, Selector};
|
use scraper::{ElementRef, Html, Selector};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
use crate::{cli::Opt, queue, util::wrap_html, ILIAS_URL, iliasignore::IliasIgnore};
|
use crate::{cli::Opt, iliasignore::IliasIgnore, queue, util::wrap_html, ILIAS_URL};
|
||||||
|
|
||||||
pub mod course;
|
pub mod course;
|
||||||
pub mod exercise;
|
pub mod exercise;
|
||||||
@ -221,7 +221,7 @@ impl ILIAS {
|
|||||||
}
|
}
|
||||||
unreachable!()
|
unreachable!()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_error_response(html: &Html) -> bool {
|
pub fn is_error_response(html: &Html) -> bool {
|
||||||
html.select(&ALERT_DANGER).next().is_some()
|
html.select(&ALERT_DANGER).next().is_some()
|
||||||
}
|
}
|
||||||
@ -285,7 +285,13 @@ impl ILIAS {
|
|||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
Ok((ILIAS::get_items(&html), main_text, html.select(&LINKS).flat_map(|x| x.value().attr("href").map(|x| x.to_owned())).collect()))
|
Ok((
|
||||||
|
ILIAS::get_items(&html),
|
||||||
|
main_text,
|
||||||
|
html.select(&LINKS)
|
||||||
|
.flat_map(|x| x.value().attr("href").map(|x| x.to_owned()))
|
||||||
|
.collect(),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_course_content_tree(&self, ref_id: &str, cmd_node: &str) -> Result<Vec<Object>> {
|
pub async fn get_course_content_tree(&self, ref_id: &str, cmd_node: &str) -> Result<Vec<Object>> {
|
||||||
|
@ -1,66 +1,67 @@
|
|||||||
use std::{path::{Path, PathBuf, Component}, ffi::OsString};
|
use std::{
|
||||||
|
ffi::OsString,
|
||||||
|
path::{Component, Path, PathBuf},
|
||||||
|
};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use ignore::gitignore::Gitignore;
|
use ignore::gitignore::Gitignore;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct IliasIgnore {
|
pub struct IliasIgnore {
|
||||||
ignores: Vec<IgnoreFile>
|
ignores: Vec<IgnoreFile>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IliasIgnore {
|
impl IliasIgnore {
|
||||||
pub fn load(mut path: PathBuf) -> Result<Self> {
|
pub fn load(mut path: PathBuf) -> Result<Self> {
|
||||||
let mut ignores = Vec::new();
|
let mut ignores = Vec::new();
|
||||||
let mut prefix = Vec::new();
|
let mut prefix = Vec::new();
|
||||||
// example scenario:
|
// example scenario:
|
||||||
// path = /KIT/ILIAS/SS 23/Next Generation Internet
|
// path = /KIT/ILIAS/SS 23/Next Generation Internet
|
||||||
// iliasignore in ILIAS/.iliasignore: prefix = SS 23/Next Generation Internet/
|
// iliasignore in ILIAS/.iliasignore: prefix = SS 23/Next Generation Internet/
|
||||||
// iliasignore in Next Generation Internet/.iliasignore: prefix = ""
|
// iliasignore in Next Generation Internet/.iliasignore: prefix = ""
|
||||||
loop {
|
loop {
|
||||||
let (ignore, error) = Gitignore::new(path.join(".iliasignore"));
|
let (ignore, error) = Gitignore::new(path.join(".iliasignore"));
|
||||||
if let Some(err) = error {
|
if let Some(err) = error {
|
||||||
warning!(err);
|
warning!(err);
|
||||||
}
|
}
|
||||||
if ignore.len() > 0 {
|
if ignore.len() > 0 {
|
||||||
ignores.push(IgnoreFile {
|
ignores.push(IgnoreFile {
|
||||||
ignore,
|
ignore,
|
||||||
prefix: prefix.iter().fold(OsString::new(), |mut acc, el| {
|
prefix: prefix.iter().fold(OsString::new(), |mut acc, el| {
|
||||||
acc.push(el);
|
acc.push(el);
|
||||||
acc.push("/");
|
acc.push("/");
|
||||||
acc
|
acc
|
||||||
})
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if let Some(last) = path.components().last() {
|
if let Some(last) = path.components().last() {
|
||||||
match last {
|
match last {
|
||||||
Component::Normal(name) => prefix.insert(0, name.to_owned()),
|
Component::Normal(name) => prefix.insert(0, name.to_owned()),
|
||||||
_ => break
|
_ => break,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
path.pop();
|
path.pop();
|
||||||
}
|
}
|
||||||
Ok(IliasIgnore {
|
Ok(IliasIgnore { ignores })
|
||||||
ignores
|
}
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn should_ignore(&self, path: &Path, is_dir: bool) -> bool {
|
pub fn should_ignore(&self, path: &Path, is_dir: bool) -> bool {
|
||||||
for ignore_file in &self.ignores {
|
for ignore_file in &self.ignores {
|
||||||
let mut full_path = ignore_file.prefix.clone();
|
let mut full_path = ignore_file.prefix.clone();
|
||||||
full_path.push(path.as_os_str());
|
full_path.push(path.as_os_str());
|
||||||
let matched = ignore_file.ignore.matched(&full_path, is_dir);
|
let matched = ignore_file.ignore.matched(&full_path, is_dir);
|
||||||
if matched.is_whitelist() {
|
if matched.is_whitelist() {
|
||||||
return false;
|
return false;
|
||||||
} else if matched.is_ignore() {
|
} else if matched.is_ignore() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
struct IgnoreFile {
|
struct IgnoreFile {
|
||||||
ignore: Gitignore,
|
ignore: Gitignore,
|
||||||
prefix: OsString
|
prefix: OsString,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user