2022-09-24 14:53:52 +00:00
|
|
|
use log::info;
|
|
|
|
|
|
|
|
use rocket::{form::Form, get, post, response::Redirect, uri, FromForm};
|
|
|
|
use rocket_dyn_templates::{context, Template};
|
2022-09-24 10:23:54 +00:00
|
|
|
|
|
|
|
use crate::sbot;
|
|
|
|
|
2022-09-24 14:53:52 +00:00
|
|
|
#[derive(FromForm)]
|
|
|
|
pub struct PeerForm {
|
|
|
|
pub public_key: String,
|
|
|
|
}
|
|
|
|
|
2022-09-24 10:23:54 +00:00
|
|
|
#[get("/")]
|
2022-09-24 14:53:52 +00:00
|
|
|
pub async fn home() -> Template {
|
|
|
|
let whoami = match sbot::whoami().await {
|
2022-09-24 10:23:54 +00:00
|
|
|
Ok(id) => id,
|
|
|
|
Err(e) => format!("whoami call failed: {}", e),
|
2022-09-24 14:53:52 +00:00
|
|
|
};
|
|
|
|
Template::render("base", context! { whoami })
|
|
|
|
}
|
|
|
|
|
|
|
|
#[post("/subscribe", data = "<peer>")]
|
|
|
|
pub async fn subscribe_form(peer: Form<PeerForm>) -> Redirect {
|
|
|
|
info!("Subscribing to peer {}", &peer.public_key);
|
|
|
|
Redirect::to(uri!(home))
|
|
|
|
}
|
|
|
|
|
|
|
|
#[post("/unsubscribe", data = "<peer>")]
|
|
|
|
pub async fn unsubscribe_form(peer: Form<PeerForm>) -> Redirect {
|
|
|
|
info!("Unsubscribing to peer {}", &peer.public_key);
|
|
|
|
Redirect::to(uri!(home))
|
2022-09-24 10:23:54 +00:00
|
|
|
}
|