From eca795475831da0d8a704c37bb591b2670407c27 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Wed, 20 Apr 2022 00:01:52 +0200 Subject: chore(tgsa): Remove shortening of image links The link shortening was in place because posts with image URLs that were too long would not get recognised as valid image links. astral has fixed this after my report: https://forums.somethingawful.com/showthread.php?threadid=3999866 I verified this with the example post that has a bunch of images and such in it. Thanks astral! Change-Id: I60e90fd52020ee5464c931a4dde91382c8a149ab Reviewed-on: https://cl.tvl.fyi/c/depot/+/5481 Reviewed-by: tazjin Autosubmit: tazjin Tested-by: BuildkiteCI --- users/tazjin/tgsa/src/main.rs | 32 +++++++------------------------- 1 file changed, 7 insertions(+), 25 deletions(-) diff --git a/users/tazjin/tgsa/src/main.rs b/users/tazjin/tgsa/src/main.rs index deae6a8150..14e2162f4d 100644 --- a/users/tazjin/tgsa/src/main.rs +++ b/users/tazjin/tgsa/src/main.rs @@ -126,38 +126,20 @@ fn parse_tgmessage(embed: &str) -> Result { }) } -fn shorten_link(link: &str) -> Result { - let mut url = url::Url::parse("https://tinyurl.com/api-create.php")?; - url.query_pairs_mut().clear().append_pair("url", link); - - let request = url.as_str(); - - let response = crimp::Request::get(request) - .send() - .context("failed to shorten URL")? - .as_string() - .context("failed to decode shortened URL")? - .error_for_status(|resp| { - anyhow!("tinyurl request failed: {} ({})", resp.body, resp.status) - })?; - - Ok(response.body.trim().into()) -} - -fn to_bbcode(link: &TgLink, msg: &TgMessage) -> Result { +fn to_bbcode(link: &TgLink, msg: &TgMessage) -> String { let mut out = String::new(); out.push_str(&format!("[quote=\"{}\"]\n", msg.author)); for video in &msg.videos { out.push_str(&format!("[url=\"{}\"]", link.to_url())); - out.push_str(&format!("[img]{}[/img]", shorten_link(video)?)); + out.push_str(&format!("[img]{}[/img]", video)); out.push_str("[/url]\n"); out.push_str("[sub](Click thumbnail to open video)[/sub]\n") } for photo in &msg.photos { - out.push_str(&format!("[timg]{}[/timg]\n", shorten_link(photo)?)); + out.push_str(&format!("[timg]{}[/timg]\n", photo)); } if msg.has_audio { @@ -179,7 +161,7 @@ fn to_bbcode(link: &TgLink, msg: &TgMessage) -> Result { out.push_str("\n[/quote]\n"); - Ok(out) + out } type Cache = RwLock>; @@ -192,7 +174,7 @@ fn handle_tg_link(cache: &Cache, link: &TgLink) -> Result { let embed = fetch_embed(&link)?; let msg = parse_tgmessage(&embed)?; - let bbcode = to_bbcode(&link, &msg).context("failed to make bbcode")?; + let bbcode = to_bbcode(&link, &msg); cache.write().unwrap().insert(link.clone(), bbcode.clone()); @@ -214,8 +196,8 @@ this is a stupid program that lets you turn telegram message links into BBcode suitable for pasting on somethingawful dot com you can use it by putting a valid telegram message link in the url and -waiting a few seconds (yes it's currently slow, yes it's SA's fault, -yes I could work around but can't be bothered atm) +waiting for some bbcode to show up. if there are images in the post the +links will be very long, don't let this scare you. for example: -- cgit 1.4.1