extern crate core;
use std::path::PathBuf;
use dialoguer::Input;
use eyre::WrapErr;
use serde::{Deserialize, Serialize};
use crate::app::commands::admin;
pub mod anythingllm;
pub mod app;
pub mod zotero;
#[derive(Serialize, Deserialize, Debug)]
pub struct Config {
pub zotero_user_id: String,
pub zotero_api_key: String,
pub zotero_library_root_path: String,
pub anythingllm_api_key: String,
pub anythingllm_ip: String,
pub anythingllm_port: String,
}
impl Config {
pub fn from_file() -> eyre::Result<Self> {
let config_path = Config::get_config_path();
let file = std::fs::File::open(config_path)?;
let config: Config = serde_json::from_reader(file)?;
Ok(config)
}
pub fn check_config() -> eyre::Result<PathBuf> {
let config_path = Config::get_config_path();
if std::fs::File::open(&config_path).is_err() {
admin::configure(&config_path).wrap_err("couldn't configure")?;
}
Ok(config_path)
}
fn get_config_path() -> PathBuf {
let dirs = directories_next::ProjectDirs::from("com", "richardlyon", "aza").unwrap();
dirs.config_dir().join("config.json")
}
}
pub fn get_config_parameters() -> Config {
let zotero_user_id: String = Input::new()
.with_prompt("Zotero User ID")
.interact_text()
.unwrap();
let zotero_api_key: String = Input::new()
.with_prompt("Zotero Api Key")
.interact_text()
.unwrap();
let zotero_library_root_path = Input::new()
.with_prompt("Zotero Library Root Path")
.interact_text()
.unwrap();
let anythingllm_api_key = Input::new()
.with_prompt("AnythingLLM Api Key")
.interact_text()
.unwrap();
let anythingllm_ip = Input::new()
.with_prompt("AnythingLLM IP")
.interact_text()
.unwrap();
let anythingllm_port = Input::new()
.with_prompt("AnythingLLM Port")
.interact_text()
.unwrap();
Config {
zotero_user_id,
zotero_api_key,
zotero_library_root_path,
anythingllm_api_key,
anythingllm_ip,
anythingllm_port,
}
}