Compare commits
1 Commits
Author | SHA1 | Date |
---|---|---|
Daan Wynen | 417e6c2410 |
|
@ -25,5 +25,5 @@ async fn rocket() -> _ {
|
||||||
rocket::build()
|
rocket::build()
|
||||||
.manage(db)
|
.manage(db)
|
||||||
.attach(Template::fairing())
|
.attach(Template::fairing())
|
||||||
.mount("/", routes![home, subscribe_form, unsubscribe_form])
|
.mount("/", routes![home, subscribe_form, unsubscribe_form, about_start, about_form])
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,41 @@ pub async fn home(flash: Option<FlashMessage<'_>>) -> Template {
|
||||||
Template::render("base", context! { whoami, flash })
|
Template::render("base", context! { whoami, flash })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[get("/about")]
|
||||||
|
pub async fn about_start() -> Template {
|
||||||
|
Template::render("about", context! {})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[post("/about", data = "<peer>")]
|
||||||
|
pub async fn about_form(peer: Form<PeerForm>) -> Result<Template, Flash<Redirect>> {
|
||||||
|
info!("Showing follow information about peer {}", &peer.public_key);
|
||||||
|
|
||||||
|
let whoami = match sbot::whoami().await {
|
||||||
|
Ok(value) => value,
|
||||||
|
Err(e) => return Err(Flash::error(Redirect::to(uri!(about_start)), e)),
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Err(e) = utils::validate_public_key(&peer.public_key) {
|
||||||
|
let validation_err_msg = format!("Public key {} is invalid: {}", &peer.public_key, e);
|
||||||
|
warn!("{}", validation_err_msg);
|
||||||
|
return Err(Flash::error(Redirect::to(uri!(about_start)), validation_err_msg));
|
||||||
|
}
|
||||||
|
info!("Public key {} is valid.", &peer.public_key);
|
||||||
|
|
||||||
|
let follow_status = match sbot::is_following(&whoami, &peer.public_key).await {
|
||||||
|
Ok(status) => status,
|
||||||
|
Err(e) => {
|
||||||
|
warn!("{}", e);
|
||||||
|
return Err(Flash::error(Redirect::to(uri!(about_start)), e));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let success_msg = format!("Follow status for {} : '{}'", &peer.public_key, follow_status);
|
||||||
|
info!("{}", success_msg);
|
||||||
|
|
||||||
|
Ok(Template::render("about", context! { whoami, peer_pubkey: &peer.public_key, status: follow_status }))
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#[post("/subscribe", data = "<peer>")]
|
#[post("/subscribe", data = "<peer>")]
|
||||||
pub async fn subscribe_form(db: &State<Database>, peer: Form<PeerForm>) -> Result<Redirect, Flash<Redirect>> {
|
pub async fn subscribe_form(db: &State<Database>, peer: Form<PeerForm>) -> Result<Redirect, Flash<Redirect>> {
|
||||||
info!("Subscribing to peer {}", &peer.public_key);
|
info!("Subscribing to peer {}", &peer.public_key);
|
||||||
|
|
|
@ -87,12 +87,12 @@ pub async fn unfollow_if_not_following(remote_peer: &str) -> Result<(), String>
|
||||||
info!("Seeing whether we should unfollow {}", remote_peer);
|
info!("Seeing whether we should unfollow {}", remote_peer);
|
||||||
if let Ok(whoami) = whoami().await {
|
if let Ok(whoami) = whoami().await {
|
||||||
match is_following(&whoami, remote_peer).await {
|
match is_following(&whoami, remote_peer).await {
|
||||||
Ok(status) if status.as_str() != "true" => {
|
Ok(status) if status != "true" => {
|
||||||
info!("Status: '{}'", status);
|
info!("Status: '{}'", status);
|
||||||
info!("Already not following peer {}. No further action taken", &remote_peer);
|
info!("Already not following peer {}. No further action taken", &remote_peer);
|
||||||
Ok(())
|
Ok(())
|
||||||
},
|
},
|
||||||
Ok(status) if status.as_str() == "true" => {
|
Ok(status) if status == "true" => {
|
||||||
info!("Status: '{}'", status);
|
info!("Status: '{}'", status);
|
||||||
match unfollow_peer(remote_peer).await {
|
match unfollow_peer(remote_peer).await {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>lykin check</title>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>lykin <code>follow</code> checker</h1>
|
||||||
|
<form action="/about" method="post">
|
||||||
|
<label for="public_key">Public Key</label>
|
||||||
|
<input type="text"
|
||||||
|
id="public_key"
|
||||||
|
name="public_key"
|
||||||
|
maxlength=53
|
||||||
|
style="font-family: monospace; width: 55ch;"
|
||||||
|
{% if peer_pubkey %}
|
||||||
|
value="{{ peer_pubkey }}"
|
||||||
|
{% endif %}
|
||||||
|
>
|
||||||
|
<input type="submit" value="Check">
|
||||||
|
</form>
|
||||||
|
{% if flash and flash.kind == "error" %}
|
||||||
|
<p style="color: red;">[ {{ flash.message }} ]</p>
|
||||||
|
{% endif %}</p>
|
||||||
|
|
||||||
|
{% if peer_pubkey and whoami and status %}
|
||||||
|
<pre>
|
||||||
|
me: {{ whoami }}
|
||||||
|
peer: {{ peer_pubkey }}
|
||||||
|
status: {{ status }}
|
||||||
|
</pre>
|
||||||
|
{% endif %}</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -7,12 +7,13 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>lykin</h1>
|
<h1>lykin</h1>
|
||||||
<p>{{ whoami }}</p>
|
<p><code>{{ whoami }}</code></p>
|
||||||
<form action="/subscribe" method="post">
|
<form action="/subscribe" method="post">
|
||||||
<label for="public_key">Public Key</label>
|
<label for="public_key">Public Key</label>
|
||||||
<input type="text" id="public_key" name="public_key" maxlength=53>
|
<input type="text" id="public_key" name="public_key" maxlength=53 style="font-family: monospace; width: 55ch;" >
|
||||||
<input type="submit" value="subscribe">
|
<br />
|
||||||
<input type="submit" value="unsubscribe" formaction="/unsubscribe">
|
<input type="submit" value="Subscribe">
|
||||||
|
<input type="submit" value="Unsubscribe" formaction="/unsubscribe">
|
||||||
</form>
|
</form>
|
||||||
{% if flash and flash.kind == "error" %}
|
{% if flash and flash.kind == "error" %}
|
||||||
<p style="color: red;">[ {{ flash.message }} ]</p>
|
<p style="color: red;">[ {{ flash.message }} ]</p>
|
||||||
|
|
Loading…
Reference in New Issue