Change subscription to get. Add subs to settings.

This commit is contained in:
Matthew Crossman 2021-01-30 22:27:49 +11:00
parent dc2030e6f3
commit 449899962a
No known key found for this signature in database
GPG key ID: C6B942B019794CC2
5 changed files with 62 additions and 21 deletions

View file

@ -100,7 +100,7 @@ async fn main() -> std::io::Result<()> {
.route("/", web::get().to(subreddit::page))
.route("/{sort:hot|new|top|rising|controversial}/", web::get().to(subreddit::page))
// Handle subscribe/unsubscribe
.route("/{action:subscribe|unsubscribe}/", web::post().to(subreddit::subscriptions))
.route("/{action:subscribe|unsubscribe}/", web::get().to(subreddit::subscriptions))
// View post on subreddit
.service(
web::scope("/comments/{id}/{title}")

View file

@ -103,7 +103,16 @@ pub async fn subscriptions(req: HttpRequest) -> HttpResponse {
}
// Redirect back to subreddit
let path = format!("/r/{}", sub);
// check for redirect parameter if unsubscribing from outside sidebar
let redirect_path = param(&format!("{}?{}", req.path(), req.query_string()), "redirect");
let path;
if redirect_path.len() > 1 && redirect_path.chars().nth(0).unwrap() == '/' {
path = redirect_path;
} else {
path = format!("/r/{}", sub);
}
res
.content_type("text/html")
.set_header("Location", path.to_string())