aboutsummaryrefslogtreecommitdiff
path: root/src/util/web.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/web.rs')
-rw-r--r--src/util/web.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/util/web.rs b/src/util/web.rs
new file mode 100644
index 0000000..77e20a3
--- /dev/null
+++ b/src/util/web.rs
@@ -0,0 +1,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)
+}