Fix short links again. Just using a split

This commit is contained in:
Peter Sawyer 2023-11-21 21:34:13 -08:00
parent 469aff0689
commit 2d64c092ea

View File

@ -18,7 +18,6 @@ use clap::{Arg, ArgAction, Command};
use futures_lite::FutureExt; use futures_lite::FutureExt;
use hyper::{header::HeaderValue, Body, Request, Response}; use hyper::{header::HeaderValue, Body, Request, Response};
use url::Url;
mod client; mod client;
use client::{canonical_path, proxy}; use client::{canonical_path, proxy};
@ -320,13 +319,8 @@ async fn main() {
// Share link // Share link
Some(id) if (8..12).contains(&id.len()) => match canonical_path(format!("/r/{}/s/{}", sub, id)).await { Some(id) if (8..12).contains(&id.len()) => match canonical_path(format!("/r/{}/s/{}", sub, id)).await {
Ok(path_opt) => match path_opt { Ok(Some(path)) => Ok(redirect(path.split('?').next().unwrap_or_default().to_string())),
Some(path) => match Url::parse(&path) { Ok(None) => error(req, "Post ID is invalid. It may point to a post on a community that has been banned.").await,
Ok(parsed_path) => Ok(redirect(parsed_path.path().to_string())),
_ => error(req, "Bad response from reddit.com").await,
},
None => error(req, "Post ID is invalid. It may point to a post on a community that has been banned.").await,
},
Err(e) => error(req, e).await, Err(e) => error(req, e).await,
}, },