Use the unified config in the web UI

This commit is contained in:
Olivier 'reivilibre' 2022-04-05 22:17:28 +01:00
parent 340b4e29a6
commit dd0097c1aa
6 changed files with 19 additions and 10 deletions

View File

@ -60,6 +60,7 @@ pub async fn main() -> anyhow::Result<()> {
})
.connect(
&web_config
.web
.sqlite_db_path
.to_str()
.context("SQLite DB path should be UTF-8")?,

View File

@ -57,6 +57,7 @@ pub async fn main() -> anyhow::Result<()> {
})
.connect(
&web_config
.web
.sqlite_db_path
.to_str()
.context("SQLite DB path should be UTF-8")?,

View File

@ -23,12 +23,13 @@ async fn main() -> anyhow::Result<()> {
)
.init();
let config_path =
PathBuf::from(std::env::var("QP_WEB_CONFIG").unwrap_or_else(|_| "qp_web.ron".to_owned()));
let config_path = PathBuf::from(
std::env::var("QUICKPEEP_CONFIG").unwrap_or_else(|_| "quickpeep.ron".to_owned()),
);
if !config_path.exists() {
bail!(
"Config path {:?} doesn't exist. QP_WEB_CONFIG env var overrides.",
"Config path {:?} doesn't exist. QUICKPEEP_CONFIG env var overrides.",
config_path
);
}
@ -54,6 +55,7 @@ async fn main() -> anyhow::Result<()> {
})
.connect(
&web_config
.web
.sqlite_db_path
.to_str()
.context("SQLite DB path should be UTF-8")?,

View File

@ -15,9 +15,14 @@ pub struct SeedCollectionConfig {
#[derive(Debug, Clone, Deserialize)]
pub struct WebConfig {
pub web: WebOnlyConfig,
pub index: BackendConfig,
}
#[derive(Debug, Clone, Deserialize)]
pub struct WebOnlyConfig {
pub seed_collection: SeedCollectionConfig,
pub sqlite_db_path: PathBuf,
pub index: BackendConfig,
/// Name, URL pairs
pub contact: Vec<(String, String)>,
}

View File

@ -33,7 +33,7 @@ pub async fn search_root(Extension(web_config): Extension<WebConfig>) -> impl In
TemplatedHtml(SearchTemplate {
search_term: String::with_capacity(0),
results: vec![],
contact: web_config.contact.clone(),
contact: web_config.web.contact.clone(),
})
}
@ -75,6 +75,6 @@ pub async fn search_search_inner(
Ok(TemplatedHtml(SearchTemplate {
search_term: params.q.clone(),
results,
contact: web_config.contact.clone(),
contact: web_config.web.contact.clone(),
}))
}

View File

@ -37,13 +37,13 @@ pub async fn seed_collection_root(
Extension(web_config): Extension<WebConfig>,
) -> impl IntoResponse {
// TODO(perf): cloning is a bit ugly; can we do better?
let seed_config = &web_config.seed_collection;
let seed_config = &web_config.web.seed_collection;
TemplatedHtml(SeedCollectionFormTemplate {
column1: seed_config.column1.clone(),
column2: seed_config.column2.clone(),
column3: seed_config.column3.clone(),
thanks_for_submitting: false,
contact: web_config.contact.clone(),
contact: web_config.web.contact.clone(),
})
}
@ -67,7 +67,7 @@ pub async fn seed_collection_root_post_inner(
eprintln!("{:?}", form);
let mut tags = BTreeSet::new();
let seed_config = &web_config.seed_collection;
let seed_config = &web_config.web.seed_collection;
for tag_group in itertools::chain!(
&seed_config.column1,
@ -117,7 +117,7 @@ pub async fn seed_collection_root_post_inner(
column2: seed_config.column2.clone(),
column3: seed_config.column3.clone(),
thanks_for_submitting: true,
contact: web_config.contact.clone(),
contact: web_config.web.contact.clone(),
}))
}