blob: 77e20a3e15cc01fee62c5d076df05e68b0c91604 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
use anyhow::{Context, Error, Result};
use reqwest::{get, Url};
// TODO: Either catinator should have a URL shortening utility module,
// or we should start our own service
pub(crate) async fn shorten_url(url: &str) -> Result<String, Error> {
// This just uses the first service gonzobot uses too
let short_url = get(Url::parse(&format!(
"https://is.gd/create.php?format=simple&url={}",
url
))
.context("Failed to parse url")?)
.await
.context("Failed to make request")?
.text()
.await
.context("failed to get request response text")?;
Ok(short_url)
}
|