diff --git a/src/client.rs b/src/client.rs index ad58758..ccc96bf 100644 --- a/src/client.rs +++ b/src/client.rs @@ -55,14 +55,14 @@ fn request(url: String) -> Boxed, String>> { let client: client::Client<_, hyper::Body> = client::Client::builder().build(https); let builder = Request::builder() - .method("GET") - .uri(&url) - .header("User-Agent", format!("web:libreddit:{}", env!("CARGO_PKG_VERSION"))) - .header("Host", "www.reddit.com") - .header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8") - .header("Accept-Language", "en-US,en;q=0.5") - .header("Connection", "keep-alive") - .body(Body::empty()); + .method("GET") + .uri(&url) + .header("User-Agent", format!("web:libreddit:{}", env!("CARGO_PKG_VERSION"))) + .header("Host", "www.reddit.com") + .header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8") + .header("Accept-Language", "en-US,en;q=0.5") + .header("Connection", "keep-alive") + .body(Body::empty()); async move { match builder { @@ -84,7 +84,7 @@ fn request(url: String) -> Boxed, String>> { } Err(e) => Err(e.to_string()), }, - Err(_) => Err("Post url contains non-ASCII characters".to_string()) + Err(_) => Err("Post url contains non-ASCII characters".to_string()), } } .boxed() diff --git a/src/main.rs b/src/main.rs index daa3320..80f6071 100644 --- a/src/main.rs +++ b/src/main.rs @@ -162,6 +162,7 @@ async fn main() { app.at("/u/:name/comments/:id/:title").get(|r| post::item(r).boxed()); app.at("/u/:name/comments/:id/:title/:comment_id").get(|r| post::item(r).boxed()); + app.at("/user/[deleted]").get(|req| error(req, "User has deleted their account".to_string()).boxed()); app.at("/user/:name").get(|r| user::profile(r).boxed()); app.at("/user/:name/comments/:id").get(|r| post::item(r).boxed()); app.at("/user/:name/comments/:id/:title").get(|r| post::item(r).boxed()); @@ -183,22 +184,28 @@ async fn main() { app.at("/r/:sub/search").get(|r| search::find(r).boxed()); - app.at("/r/:sub/wiki/").get(|r| subreddit::wiki(r).boxed()); + app + .at("/r/:sub/w") + .get(|r| async move { Ok(redirect(format!("/r/{}/wiki", r.param("sub").unwrap_or_default()))) }.boxed()); + app + .at("/r/:sub/w/:page") + .get(|r| async move { Ok(redirect(format!("/r/{}/wiki/{}", r.param("sub").unwrap_or_default(), r.param("wiki").unwrap_or_default()))) }.boxed()); + app.at("/r/:sub/wiki").get(|r| subreddit::wiki(r).boxed()); app.at("/r/:sub/wiki/:page").get(|r| subreddit::wiki(r).boxed()); - app.at("/r/:sub/w").get(|r| subreddit::wiki(r).boxed()); - app.at("/r/:sub/w/:page").get(|r| subreddit::wiki(r).boxed()); app.at("/r/:sub/:sort").get(|r| subreddit::community(r).boxed()); // Comments handler - app.at("/comments/:id/").get(|r| post::item(r).boxed()); + app.at("/comments/:id").get(|r| post::item(r).boxed()); // Front page app.at("/").get(|r| subreddit::community(r).boxed()); // View Reddit wiki - app.at("/w").get(|r| subreddit::wiki(r).boxed()); - app.at("/w/:page").get(|r| subreddit::wiki(r).boxed()); + app.at("/w").get(|_| async move { Ok(redirect("/wiki".to_string())) }.boxed()); + app + .at("/w/:page") + .get(|r| async move { Ok(redirect(format!("/wiki/{}", r.param("page").unwrap_or_default()))) }.boxed()); app.at("/wiki").get(|r| subreddit::wiki(r).boxed()); app.at("/wiki/:page").get(|r| subreddit::wiki(r).boxed()); diff --git a/src/user.rs b/src/user.rs index 4b2633a..fdbc128 100644 --- a/src/user.rs +++ b/src/user.rs @@ -21,7 +21,11 @@ struct UserTemplate { // FUNCTIONS pub async fn profile(req: Request) -> Result, String> { // Build the Reddit JSON API path - let path = format!("{}.json?{}&raw_json=1", req.uri().path(), req.uri().query().unwrap_or_default()); + let path = format!( + "/user/{}.json?{}&raw_json=1", + req.param("name").unwrap_or("reddit".to_string()), + req.uri().query().unwrap_or_default() + ); // Retrieve other variables from Libreddit request let sort = param(&path, "sort");