Add "--print-tripcode" option to ptth_server

main
_ 2020-11-24 23:56:43 +00:00
parent 1b9eabf458
commit bfe07fddc3
3 changed files with 32 additions and 4 deletions

View File

@ -17,6 +17,9 @@ struct Opt {
#[structopt (long)]
asset_root: Option <PathBuf>,
#[structopt (long)]
print_tripcode: bool,
}
fn main () -> Result <(), Box <dyn Error>> {
@ -26,6 +29,11 @@ fn main () -> Result <(), Box <dyn Error>> {
let path = opt.config_path.clone ().unwrap_or_else (|| PathBuf::from ("./config/ptth_server.toml"));
let config_file: ptth::server::ConfigFile = ptth::load_toml::load (&path);
if opt.print_tripcode {
println! (r#""{}" = "{}""#, config_file.name, config_file.tripcode ());
return Ok (());
}
let mut rt = if false {
debug! ("Trying to use less RAM");

View File

@ -119,6 +119,12 @@ pub struct ConfigFile {
pub file_server_root: Option <PathBuf>,
}
impl ConfigFile {
pub fn tripcode (&self) -> String {
base64::encode (blake3::hash (self.api_key.as_bytes ()).as_bytes ())
}
}
#[derive (Default)]
pub struct Config {
pub relay_url: String,
@ -145,10 +151,8 @@ pub async fn run_server (
server_name: config_file.name.clone (),
};
let tripcode = base64::encode (blake3::hash (config_file.api_key.as_bytes ()).as_bytes ());
info! ("Server name is {}", config_file.name);
info! ("Tripcode is {}", tripcode);
info! ("Tripcode is {}", config_file.tripcode ());
let mut headers = reqwest::header::HeaderMap::new ();
headers.insert ("X-ApiKey", config_file.api_key.try_into ().unwrap ());
@ -255,3 +259,20 @@ pub async fn run_server (
Ok (())
}
#[cfg (test)]
mod tests {
use super::*;
#[test]
fn tripcode_algo () {
let config = ConfigFile {
name: "TestName".into (),
api_key: "PlaypenCausalPlatformCommodeImproveCatalyze".into (),
relay_url: "".into (),
file_server_root: None,
};
assert_eq! (config.tripcode (), "A9rPwZyY89Ag4TJjMoyYA2NeGOm99Je6rq1s0rg8PfY=".to_string ());
}
}

View File

@ -1,4 +1,3 @@
- Print tripcode without running the server
- Reload relay config (or at least tripcodes) without downtime
- "Preview as" feature for Markdown (It's not threaded through the relay yet)
- Remote `tail -f` (_Complicated_) (Maybe use chunked encoding or something?)