diff --git a/Cargo.toml b/Cargo.toml index a10f479..c5451be 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "libreddit" description = " Alternative private front-end to Reddit" license = "AGPL-3.0" repository = "https://github.com/spikecodes/libreddit" -version = "0.5.3" +version = "0.5.4" authors = ["spikecodes <19519553+spikecodes@users.noreply.github.com>"] edition = "2018" diff --git a/src/client.rs b/src/client.rs index ccc96bf..eaf9092 100644 --- a/src/client.rs +++ b/src/client.rs @@ -3,7 +3,6 @@ use futures_lite::{future::Boxed, FutureExt}; use hyper::{body::Buf, client, Body, Request, Response, Uri}; use serde_json::Value; use std::{result::Result, str::FromStr}; -// use async_recursion::async_recursion; use crate::server::RequestExt; diff --git a/src/main.rs b/src/main.rs index 13b629a..14007fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -175,6 +175,10 @@ async fn main() { // Subreddit services app.at("/r/:sub").get(|r| subreddit::community(r).boxed()); + app + .at("/r/u_:name") + .get(|r| async move { Ok(redirect(format!("/user/{}", r.param("name").unwrap_or_default()))) }.boxed()); + app.at("/r/:sub/subscribe").post(|r| subreddit::subscriptions(r).boxed()); app.at("/r/:sub/unsubscribe").post(|r| subreddit::subscriptions(r).boxed()); @@ -215,18 +219,13 @@ async fn main() { // Handle about pages app.at("/about").get(|req| error(req, "About pages aren't added yet".to_string()).boxed()); - app.at("/:id").get(|req: Request| { - async { - match req.param("id").as_deref() { - // Sort front page - Some("best") | Some("hot") | Some("new") | Some("top") | Some("rising") | Some("controversial") => subreddit::community(req).await, - // Short link for post - Some(id) if id.len() > 4 && id.len() < 7 => post::item(req).await, - // Error message for unknown pages - _ => error(req, "Nothing here".to_string()).await, - } - } - .boxed() + app.at("/:id").get(|req: Request| match req.param("id").as_deref() { + // Sort front page + Some("best") | Some("hot") | Some("new") | Some("top") | Some("rising") | Some("controversial") => subreddit::community(req).boxed(), + // Short link for post + Some(id) if id.len() > 4 && id.len() < 7 => post::item(req).boxed(), + // Error message for unknown pages + _ => error(req, "Nothing here".to_string()).boxed(), }); // Default service in case no routes match diff --git a/src/utils.rs b/src/utils.rs index 76250c4..76509da 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -451,9 +451,9 @@ pub fn rewrite_urls(text: &str) -> String { // Append `m` and `k` for millions and thousands respectively pub fn format_num(num: i64) -> String { - if num >= 1_000_000 { + if num >= 1_000_000 || num <= -1_000_000 { format!("{}m", num / 1_000_000) - } else if num >= 1000 { + } else if num >= 1000 || num <= -1000 { format!("{}k", num / 1_000) } else { num.to_string()