Moved fediverse config path to constant
This commit is contained in:
parent
c96ff09128
commit
d467fd261a
|
@ -6,6 +6,9 @@ use elefren::{
|
|||
status_builder::Visibility,
|
||||
Language, Mastodon, MastodonClient, Registration, StatusBuilder,
|
||||
};
|
||||
|
||||
const FEDIVERSE_TOML_PATH: &str = "fediverse.toml";
|
||||
|
||||
pub trait Publisher {
|
||||
fn publish(&self, content: String) -> Option<Box<dyn Error>>;
|
||||
}
|
||||
|
@ -16,7 +19,7 @@ pub struct FediversePublisher {
|
|||
|
||||
impl FediversePublisher {
|
||||
pub fn new(fedi_url: String) -> Result<FediversePublisher, Box<dyn Error>> {
|
||||
let fedi = if let Ok(data) = toml::from_file("fediverse.toml") {
|
||||
let fedi = if let Ok(data) = toml::from_file(FEDIVERSE_TOML_PATH.to_string()) {
|
||||
Mastodon::from(data)
|
||||
} else {
|
||||
register(fedi_url)?
|
||||
|
@ -56,7 +59,7 @@ fn register(fedi_url: String) -> Result<Mastodon, Box<dyn Error>> {
|
|||
let fediverse = cli::authenticate(registration)?;
|
||||
|
||||
// Save app data for using on the next run.
|
||||
toml::to_file(&*fediverse, "fediverse.toml")?;
|
||||
toml::to_file(&*fediverse, FEDIVERSE_TOML_PATH.to_string())?;
|
||||
|
||||
Ok(fediverse)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue