Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ async fn main() {
Box::pin(async move {
let sub = req.param("sub").unwrap_or_default();
match req.param("id").as_deref() {
// Share link
// Subreddit post share link
Some(id) if (8..12).contains(&id.len()) => match canonical_path(format!("/r/{sub}/s/{id}"), 3).await {
Ok(Some(path)) => Ok(redirect(&path)),
Ok(None) => error(req, "Post ID is invalid. It may point to a post on a community that has been banned.").await,
Expand All @@ -384,6 +384,22 @@ async fn main() {
}
})
});
app.at("/u/:name/s/:id").get(|req: Request<Body>| {
Box::pin(async move {
let name = req.param("name").unwrap_or_default();
match req.param("id").as_deref() {
// User post share link
Some(id) if (8..12).contains(&id.len()) => match canonical_path(format!("/u/{name}/s/{id}"), 3).await {
Ok(Some(path)) => Ok(redirect(&path)),
Ok(None) => error(req, "Post ID is invalid. It may point to a post on a user that has been banned.").await,
Err(e) => error(req, &e).await,
},

// Error message for unknown pages
_ => error(req, "Nothing here").await,
}
})
});

app.at("/:id").get(|req: Request<Body>| {
Box::pin(async move {
Expand Down
Loading