Refactor redirect path setting

This commit is contained in:
spikecodes 2021-01-30 17:50:26 -08:00
parent 9b7cd1da5a
commit d62a3ab86b

View File

@ -100,18 +100,16 @@ pub async fn subscriptions(req: HttpRequest) -> HttpResponse {
// Redirect back to subreddit // Redirect back to subreddit
// check for redirect parameter if unsubscribing from outside sidebar // check for redirect parameter if unsubscribing from outside sidebar
let redirect_path = param(&req.uri().to_string(), "redirect"); let redirect_path = param(&req.uri().to_string(), "redirect");
let path; let path = if !redirect_path.is_empty() && redirect_path.starts_with('/') {
redirect_path
if redirect_path.len() > 1 && redirect_path.chars().nth(0).unwrap() == '/' {
path = redirect_path;
} else { } else {
path = format!("/r/{}", sub); format!("/r/{}", sub)
} };
res res
.content_type("text/html") .content_type("text/html")
.set_header("Location", path.to_string()) .set_header("Location", path.to_owned())
.body(format!("Redirecting to <a href=\"{0}\">{0}</a>...", path.to_string())) .body(format!("Redirecting to <a href=\"{0}\">{0}</a>...", path))
} }
pub async fn wiki(req: HttpRequest) -> HttpResponse { pub async fn wiki(req: HttpRequest) -> HttpResponse {