mirror of https://github.com/raftario/filite.git
Always generate missing config and password files
This commit is contained in:
parent
4012651741
commit
49c1ad8232
|
@ -77,6 +77,8 @@ fn main() {
|
||||||
let port = config.port;
|
let port = config.port;
|
||||||
let max_filesize = (config.max_filesize as f64 * 1.37) as usize;
|
let max_filesize = (config.max_filesize as f64 * 1.37) as usize;
|
||||||
|
|
||||||
|
println!("Listening on port {}", port);
|
||||||
|
|
||||||
HttpServer::new(move || {
|
HttpServer::new(move || {
|
||||||
App::new()
|
App::new()
|
||||||
.data(pool.clone())
|
.data(pool.clone())
|
||||||
|
|
39
src/setup.rs
39
src/setup.rs
|
@ -242,19 +242,13 @@ pub fn logger_middleware() -> Logger {
|
||||||
/// Performs the initial setup
|
/// Performs the initial setup
|
||||||
#[cfg(not(feature = "dev"))]
|
#[cfg(not(feature = "dev"))]
|
||||||
pub fn init() -> Config {
|
pub fn init() -> Config {
|
||||||
let config_dir = get_config_dir();
|
fs::create_dir_all(get_config_dir()).unwrap_or_else(|e| {
|
||||||
if !config_dir.exists() {
|
eprintln!("Can't create config directory: {}.", e);
|
||||||
fs::create_dir_all(&config_dir).unwrap_or_else(|e| {
|
process::exit(1);
|
||||||
eprintln!("Can't create config directory: {}.", e);
|
});
|
||||||
process::exit(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
println!("Generating config file...");
|
|
||||||
Config::default().write_file().unwrap_or_else(|e| {
|
|
||||||
eprintln!("Couldn't write the config file: {}", e);
|
|
||||||
process::exit(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
let password_path = get_password_path();
|
||||||
|
if !password_path.exists() {
|
||||||
let stdin = io::stdin();
|
let stdin = io::stdin();
|
||||||
let mut stdin = stdin.lock();
|
let mut stdin = stdin.lock();
|
||||||
println!("Enter the password to use:");
|
println!("Enter the password to use:");
|
||||||
|
@ -266,23 +260,22 @@ pub fn init() -> Config {
|
||||||
password = password.replace("\r", "");
|
password = password.replace("\r", "");
|
||||||
password = password.replace("\n", "");
|
password = password.replace("\n", "");
|
||||||
let password_hash = hash(&password);
|
let password_hash = hash(&password);
|
||||||
let password_path = get_password_path();
|
|
||||||
fs::write(&password_path, password_hash.as_slice()).unwrap_or_else(|e| {
|
fs::write(&password_path, password_hash.as_slice()).unwrap_or_else(|e| {
|
||||||
eprintln!("Can't write password: {}", e);
|
eprintln!("Can't write password: {}", e);
|
||||||
process::exit(1);
|
process::exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
println!(
|
|
||||||
"Almost ready. To get started, edit the config file at {} and restart.",
|
|
||||||
get_config_path().display(),
|
|
||||||
);
|
|
||||||
process::exit(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fs::create_dir_all(get_data_dir()).unwrap_or_else(|e| {
|
let config_path = get_config_path();
|
||||||
eprintln!("Can't create data directory: {}.", e);
|
if !config_path.exists() {
|
||||||
process::exit(1);
|
println!("Generating config file at {}", config_path.display());
|
||||||
});
|
let config = Config::default();
|
||||||
|
config.write_file().unwrap_or_else(|e| {
|
||||||
|
eprintln!("Couldn't write the config file: {}", e);
|
||||||
|
process::exit(1);
|
||||||
|
});
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
Config::read_file().unwrap_or_else(|e| {
|
Config::read_file().unwrap_or_else(|e| {
|
||||||
eprintln!("{}", e);
|
eprintln!("{}", e);
|
||||||
|
|
Loading…
Reference in New Issue