123456789101112131415161718192021222324 |
- use anyhow::{Context, Result};
- use url::Url;
- /// Convert relate to absolute
- pub fn relative_to_absolute(base_url: &str, relative_href: &str) -> Result<String> {
- let base_url = Url::parse(base_url).context(format!("Url::parse({})", base_url))?;
- let new_url = base_url
- .join(relative_href)
- .context(format!("join({})", relative_href))?;
- Ok(new_url.to_string())
- }
- // Should this always fetch it/save?
- pub fn fetch(client: &reqwest::blocking::Client, url: &str) -> Result<String> {
- let res = client.get(url).send()?;
- let buffer = res.text()?;
- Ok(buffer)
- }
- /// Extract filename from the end of a URL.
- pub fn filename_from_url(url: &str) -> Result<String> {
- let (_, filename) = url.rsplit_once('/').context("Failed to split URL.")?;
- Ok(filename.to_string())
- }
|