forked from cadey/maj
adapt majsite to serve cetacean.club
This commit is contained in:
parent
0ffd86c9f6
commit
4b7374b39f
|
@ -15,5 +15,6 @@ env_logger = "0"
|
||||||
percent-encoding = "2"
|
percent-encoding = "2"
|
||||||
rustls = { version = "0.18", features = ["dangerous_configuration"] }
|
rustls = { version = "0.18", features = ["dangerous_configuration"] }
|
||||||
structopt = "0.3"
|
structopt = "0.3"
|
||||||
|
dnd_dice_roller = "0.3"
|
||||||
|
|
||||||
maj = { path = "..", features = ["server"], default-features = false }
|
maj = { path = "..", features = ["server"], default-features = false }
|
|
@ -1,21 +0,0 @@
|
||||||
# maj
|
|
||||||
```
|
|
||||||
__
|
|
||||||
_____ _____ |__|
|
|
||||||
/ \ \__ \ | |
|
|
||||||
| Y Y \ / __ \_ | |
|
|
||||||
|__|_| /(____ //\__| |
|
|
||||||
\/ \/ \______|
|
|
||||||
```
|
|
||||||
|
|
||||||
A gemini ecosystem for Rust
|
|
||||||
|
|
||||||
=> gemini://gemini.circumlunar.space/ Gemini homepage
|
|
||||||
|
|
||||||
## Homepage
|
|
||||||
The main homepage for maj is on tulpa.dev:
|
|
||||||
=> https://tulpa.dev/cadey/maj
|
|
||||||
|
|
||||||
## Projects
|
|
||||||
=> /majc majc, an interactive curses client
|
|
||||||
=> /majd majd, a high-power gemini server with Lua capabilities
|
|
102
site/src/main.rs
102
site/src/main.rs
|
@ -1,4 +1,5 @@
|
||||||
use async_std::task;
|
use async_std::task;
|
||||||
|
use dnd_dice_roller::{dice::Dice, error::DiceError};
|
||||||
use maj::{
|
use maj::{
|
||||||
gemini::{Builder, Node},
|
gemini::{Builder, Node},
|
||||||
route, seg,
|
route, seg,
|
||||||
|
@ -10,10 +11,13 @@ use rustls::{
|
||||||
internal::pemfile::{certs, rsa_private_keys},
|
internal::pemfile::{certs, rsa_private_keys},
|
||||||
AllowAnyAnonymousOrAuthenticatedClient, Certificate, PrivateKey, RootCertStore, ServerConfig,
|
AllowAnyAnonymousOrAuthenticatedClient, Certificate, PrivateKey, RootCertStore, ServerConfig,
|
||||||
};
|
};
|
||||||
use std::fs::File;
|
use std::{
|
||||||
use std::io::{self, BufReader};
|
fs::File,
|
||||||
use std::path::{Path, PathBuf};
|
io::{self, BufReader},
|
||||||
use std::sync::Arc;
|
path::{Path, PathBuf},
|
||||||
|
str::FromStr,
|
||||||
|
sync::Arc,
|
||||||
|
};
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
|
|
||||||
#[derive(StructOpt, Debug)]
|
#[derive(StructOpt, Debug)]
|
||||||
|
@ -42,7 +46,7 @@ struct Options {
|
||||||
#[structopt(
|
#[structopt(
|
||||||
long = "hostname",
|
long = "hostname",
|
||||||
env = "SERVER_HOSTNAME",
|
env = "SERVER_HOSTNAME",
|
||||||
default_value = "maj.kahless.cetacean.club"
|
default_value = "cetacean.club"
|
||||||
)]
|
)]
|
||||||
hostname: String,
|
hostname: String,
|
||||||
}
|
}
|
||||||
|
@ -95,63 +99,53 @@ struct Handler {
|
||||||
files: maj::server::files::Handler,
|
files: maj::server::files::Handler,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn index() -> Result<maj::Response, maj::server::Error> {
|
async fn dice(req: Request) -> Result<Response, Error> {
|
||||||
let msg = include_bytes!("index.gmi");
|
fn dice_roll<T: Into<String>>(roll: T) -> Result<String, DiceError> {
|
||||||
Ok(Response::gemini(msg.to_vec()))
|
let mut dice = Dice::from_str(&roll.into())?;
|
||||||
}
|
|
||||||
|
|
||||||
async fn majc() -> Result<maj::Response, maj::server::Error> {
|
if dice.number_of_dice_to_roll > 100 {
|
||||||
let msg = include_bytes!("majc.gmi");
|
dice.number_of_dice_to_roll = 100;
|
||||||
Ok(Response::gemini(msg.to_vec()))
|
}
|
||||||
}
|
|
||||||
|
|
||||||
async fn need_cert(req: Request) -> Result<Response, Error> {
|
if dice.sides > 100 {
|
||||||
match req.certs {
|
dice.sides = 100
|
||||||
None => Ok(Response::need_cert("test")),
|
}
|
||||||
Some(certs) => Ok(Response::render(
|
|
||||||
Builder::new()
|
if dice.sides == 0 {
|
||||||
.heading(1, "Cert test")
|
dice.sides = 6;
|
||||||
.text(format!("{:?}", certs))
|
}
|
||||||
.build(),
|
|
||||||
)),
|
let res = dice.roll_dice();
|
||||||
|
let reply = format!(
|
||||||
|
"{}{} = {}\n",
|
||||||
|
res.dice_results,
|
||||||
|
match dice.modifier {
|
||||||
|
Some(amt) => format!(" + {}", amt),
|
||||||
|
None => "".into(),
|
||||||
|
},
|
||||||
|
res.final_result[0]
|
||||||
|
);
|
||||||
|
Ok(reply)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
async fn input(req: Request) -> Result<Response, Error> {
|
|
||||||
match req.url.query() {
|
match req.url.query() {
|
||||||
None => Ok(Response::input("test")),
|
None => Ok(Response::input(
|
||||||
|
"What do you want to roll? [n]dn[+n] [adv|dadv]",
|
||||||
|
)),
|
||||||
Some(q) => Ok({
|
Some(q) => Ok({
|
||||||
use Node::*;
|
let dice = percent_decode_str(q).decode_utf8()?;
|
||||||
let result = vec![
|
let b = Builder::new()
|
||||||
Heading {
|
.heading(1, "Dice Results")
|
||||||
level: 1,
|
.text("")
|
||||||
body: "Input test".to_string(),
|
.text(format!("You rolled {} and you got:", dice))
|
||||||
},
|
.text("")
|
||||||
Node::blank(),
|
.preformatted(format!("{}", dice_roll(dice)?));
|
||||||
Text("You gave me:".to_string()),
|
|
||||||
Preformatted(format!("{}", percent_decode_str(q).decode_utf8()?)),
|
|
||||||
];
|
|
||||||
|
|
||||||
Response::render(result)
|
Response::render(b.build())
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn user(name: String) -> Result<Response, Error> {
|
|
||||||
Ok(Response::render({
|
|
||||||
use Node::*;
|
|
||||||
|
|
||||||
vec![
|
|
||||||
Heading {
|
|
||||||
level: 1,
|
|
||||||
body: format!("{}'s user page", name),
|
|
||||||
},
|
|
||||||
Node::blank(),
|
|
||||||
Text(format!("this is a test page for {}", name)),
|
|
||||||
]
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl MajHandler for Handler {
|
impl MajHandler for Handler {
|
||||||
async fn handle(&self, req: Request) -> Result<Response, Error> {
|
async fn handle(&self, req: Request) -> Result<Response, Error> {
|
||||||
|
@ -167,11 +161,7 @@ impl MajHandler for Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
route!(req.url.path(), {
|
route!(req.url.path(), {
|
||||||
(/) => index().await;
|
(/"dice") => dice(req).await;
|
||||||
(/"cert") => need_cert(req).await;
|
|
||||||
(/"input") => input(req).await;
|
|
||||||
(/"majc") => majc().await;
|
|
||||||
(/"~"/[name: String][/rest..]) => user(name).await;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
self.files.handle(req).await
|
self.files.handle(req).await
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
```
|
|
||||||
__
|
|
||||||
_____ _____ |__| ____
|
|
||||||
/ \ \__ \ | |_/ ___\
|
|
||||||
| Y Y \ / __ \_ | |\ \___
|
|
||||||
|__|_| /(____ //\__| | \___ >
|
|
||||||
\/ \/ \______| \/
|
|
||||||
```
|
|
||||||
|
|
||||||
A curses client for Gemini!
|
|
||||||
|
|
||||||
## Homepage
|
|
||||||
The main homepage for majc is on tulpa.dev:
|
|
||||||
=> https://tulpa.dev/cadey/maj
|
|
||||||
|
|
||||||
## Important Keys
|
|
||||||
<esc>: opens the menubar
|
|
||||||
c: closes the active window
|
|
||||||
o: prompts to open a URL
|
|
||||||
h: shows history
|
|
||||||
l: shows active links in the page
|
|
||||||
q: quits majc
|
|
||||||
?: shows this screen
|
|
||||||
~: toggles the debug logging pane
|
|
Loading…
Reference in New Issue