42 lines
1.1 KiB
Rust
42 lines
1.1 KiB
Rust
use std::{
|
|
error::Error,
|
|
path::PathBuf,
|
|
};
|
|
|
|
use structopt::StructOpt;
|
|
|
|
#[derive (Debug, StructOpt)]
|
|
struct Opt {
|
|
#[structopt (name = "RELAY_URL")]
|
|
relay_url: String,
|
|
|
|
#[structopt (long)]
|
|
file_server_root: Option <PathBuf>,
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main () -> Result <(), Box <dyn Error>> {
|
|
use std::io::Read;
|
|
|
|
let config_file = {
|
|
let config_file_path = "ptth_server.toml";
|
|
|
|
let mut f = std::fs::File::open (config_file_path).expect (&format! ("Can't open {:?}", config_file_path));
|
|
let mut buffer = vec! [0u8; 4096];
|
|
let bytes_read = f.read (&mut buffer).expect (&format! ("Can't read {:?}", config_file_path));
|
|
buffer.truncate (bytes_read);
|
|
|
|
let config_s = String::from_utf8 (buffer).expect (&format! ("Can't parse {:?} as UTF-8", config_file_path));
|
|
toml::from_str (&config_s).expect (&format! ("Can't parse {:?} as TOML", config_file_path))
|
|
};
|
|
|
|
let opt = Opt::from_args ();
|
|
|
|
let opt = ptth::server::Opt {
|
|
relay_url: opt.relay_url,
|
|
file_server_root: opt.file_server_root.unwrap_or_else (|| "/home/user".into ()),
|
|
};
|
|
|
|
ptth::server::main (config_file, opt).await
|
|
}
|