➕ Add "--print-tripcode" option to ptth_server
parent
1b9eabf458
commit
bfe07fddc3
|
@ -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");
|
||||
|
||||
|
|
|
@ -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 ());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue