feat(main): relay override by environment variable
This commit is contained in:
parent
93718aaf1e
commit
1b361355b0
45
src/main.rs
45
src/main.rs
|
@ -1,4 +1,4 @@
|
||||||
use std::env::args;
|
use std::env::{args, var};
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
@ -84,26 +84,33 @@ async fn main() {
|
||||||
|
|
||||||
let client = Client::new(&keys);
|
let client = Client::new(&keys);
|
||||||
println!("My public key: {}", keys.public_key());
|
println!("My public key: {}", keys.public_key());
|
||||||
match File::open(&relayfile).map(|f| BufReader::new(f).lines().flatten()) {
|
match var("MOSTR_RELAY") {
|
||||||
Ok(lines) => {
|
Ok(relay) => {
|
||||||
for line in lines {
|
or_print(client.add_relay(relay).await);
|
||||||
or_print(client.add_relay(line).await);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
_ => {
|
||||||
eprintln!("Could not read relays file: {}", e);
|
match File::open(&relayfile).map(|f| BufReader::new(f).lines().flatten()) {
|
||||||
if let Some(line) = prompt("Relay?") {
|
Ok(lines) => {
|
||||||
let url = if line.contains("://") { line } else { "wss://".to_string() + &line };
|
for line in lines {
|
||||||
or_print(
|
or_print(client.add_relay(line).await);
|
||||||
client
|
|
||||||
.add_relay(url.clone())
|
|
||||||
.await,
|
|
||||||
).map(|bool| {
|
|
||||||
if bool {
|
|
||||||
or_print(fs::write(&relayfile, url));
|
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
};
|
Err(e) => {
|
||||||
|
eprintln!("Could not read relays file: {}", e);
|
||||||
|
if let Some(line) = prompt("Relay?") {
|
||||||
|
let url = if line.contains("://") { line } else { "wss://".to_string() + &line };
|
||||||
|
or_print(
|
||||||
|
client
|
||||||
|
.add_relay(url.clone())
|
||||||
|
.await,
|
||||||
|
).map(|bool| {
|
||||||
|
if bool {
|
||||||
|
or_print(fs::write(&relayfile, url));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue