Add (external) link validation

This commit is contained in:
Matthias Beyer 2016-02-23 11:50:42 +01:00
parent cb288eb868
commit 695ee9df9b
3 changed files with 11 additions and 0 deletions

View file

@ -6,6 +6,7 @@ authors = ["Matthias Beyer <mail@beyermatthias.de>"]
[dependencies] [dependencies]
log = "0.3.4" log = "0.3.4"
toml = "0.1.27" toml = "0.1.27"
url = "0.5.5"
[dependencies.libimagstore] [dependencies.libimagstore]
path = "../libimagstore" path = "../libimagstore"

View file

@ -8,6 +8,7 @@ use result::Result;
use toml::Value; use toml::Value;
use toml::Table; use toml::Table;
use url::Url;
#[derive(PartialOrd, Ord, Eq, PartialEq, Clone, Debug)] #[derive(PartialOrd, Ord, Eq, PartialEq, Clone, Debug)]
pub struct Link { pub struct Link {
@ -20,6 +21,10 @@ impl Link {
Link { link: s } Link { link: s }
} }
pub fn is_valid(&self) -> bool {
Url::parse(&self.link[..]).is_ok()
}
} }
#[derive(Eq, PartialEq, Clone, Debug)] #[derive(Eq, PartialEq, Clone, Debug)]
@ -41,6 +46,10 @@ impl Links {
self.links.retain(|link| l != link.clone()); self.links.retain(|link| l != link.clone());
} }
pub fn all_valid(&self) -> bool {
self.links.iter().all(|l| l.is_valid())
}
} }
impl Into<String> for Link { impl Into<String> for Link {

View file

@ -1,5 +1,6 @@
#[macro_use] extern crate log; #[macro_use] extern crate log;
extern crate toml; extern crate toml;
extern crate url;
extern crate libimagstore; extern crate libimagstore;