2021-04-09 00:22:17 +00:00
|
|
|
use regex::Regex;
|
|
|
|
|
|
|
|
pub fn get_ipfs_url(cid: &str) -> String {
|
|
|
|
format!("ipfs://{}", cid)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(thiserror::Error, Debug)]
|
|
|
|
#[error("parse error")]
|
|
|
|
pub struct ParseError;
|
|
|
|
|
|
|
|
pub fn parse_ipfs_url(url: &str) -> Result<String, ParseError> {
|
|
|
|
let regexp = Regex::new(r"ipfs://(?P<cid>\w+)").unwrap();
|
2021-11-13 17:37:31 +00:00
|
|
|
let caps = regexp.captures(url).ok_or(ParseError)?;
|
2021-04-09 00:22:17 +00:00
|
|
|
let cid = caps.name("cid")
|
|
|
|
.ok_or(ParseError)?
|
|
|
|
.as_str().to_string();
|
|
|
|
Ok(cid)
|
|
|
|
}
|