➕ Add "--print-tripcode" option to ptth_server
parent
1b9eabf458
commit
bfe07fddc3
|
@ -17,6 +17,9 @@ struct Opt {
|
||||||
|
|
||||||
#[structopt (long)]
|
#[structopt (long)]
|
||||||
asset_root: Option <PathBuf>,
|
asset_root: Option <PathBuf>,
|
||||||
|
|
||||||
|
#[structopt (long)]
|
||||||
|
print_tripcode: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main () -> Result <(), Box <dyn Error>> {
|
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 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);
|
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 {
|
let mut rt = if false {
|
||||||
debug! ("Trying to use less RAM");
|
debug! ("Trying to use less RAM");
|
||||||
|
|
||||||
|
|
|
@ -119,6 +119,12 @@ pub struct ConfigFile {
|
||||||
pub file_server_root: Option <PathBuf>,
|
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)]
|
#[derive (Default)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub relay_url: String,
|
pub relay_url: String,
|
||||||
|
@ -145,10 +151,8 @@ pub async fn run_server (
|
||||||
server_name: config_file.name.clone (),
|
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! ("Server name is {}", config_file.name);
|
||||||
info! ("Tripcode is {}", tripcode);
|
info! ("Tripcode is {}", config_file.tripcode ());
|
||||||
|
|
||||||
let mut headers = reqwest::header::HeaderMap::new ();
|
let mut headers = reqwest::header::HeaderMap::new ();
|
||||||
headers.insert ("X-ApiKey", config_file.api_key.try_into ().unwrap ());
|
headers.insert ("X-ApiKey", config_file.api_key.try_into ().unwrap ());
|
||||||
|
@ -255,3 +259,20 @@ pub async fn run_server (
|
||||||
|
|
||||||
Ok (())
|
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 ());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
1
todo.md
1
todo.md
|
@ -1,4 +1,3 @@
|
||||||
- Print tripcode without running the server
|
|
||||||
- Reload relay config (or at least tripcodes) without downtime
|
- Reload relay config (or at least tripcodes) without downtime
|
||||||
- "Preview as" feature for Markdown (It's not threaded through the relay yet)
|
- "Preview as" feature for Markdown (It's not threaded through the relay yet)
|
||||||
- Remote `tail -f` (_Complicated_) (Maybe use chunked encoding or something?)
|
- Remote `tail -f` (_Complicated_) (Maybe use chunked encoding or something?)
|
||||||
|
|
Loading…
Reference in New Issue