From dd0097c1aabd173e08788f0e140a93ece8fa69a4 Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Tue, 5 Apr 2022 22:17:28 +0100 Subject: [PATCH] Use the unified config in the web UI --- quickpeep/src/bin/qp-seedcoll-dump.rs | 1 + quickpeep/src/bin/qp-seedcoll-sort.rs | 1 + quickpeep/src/bin/quickpeep.rs | 8 +++++--- quickpeep/src/config.rs | 7 ++++++- quickpeep/src/web/searcher.rs | 4 ++-- quickpeep/src/web/seed_collector.rs | 8 ++++---- 6 files changed, 19 insertions(+), 10 deletions(-) diff --git a/quickpeep/src/bin/qp-seedcoll-dump.rs b/quickpeep/src/bin/qp-seedcoll-dump.rs index 4786628..c98738f 100644 --- a/quickpeep/src/bin/qp-seedcoll-dump.rs +++ b/quickpeep/src/bin/qp-seedcoll-dump.rs @@ -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")?, diff --git a/quickpeep/src/bin/qp-seedcoll-sort.rs b/quickpeep/src/bin/qp-seedcoll-sort.rs index b569a23..b24c8fa 100644 --- a/quickpeep/src/bin/qp-seedcoll-sort.rs +++ b/quickpeep/src/bin/qp-seedcoll-sort.rs @@ -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")?, diff --git a/quickpeep/src/bin/quickpeep.rs b/quickpeep/src/bin/quickpeep.rs index 56dfd82..1a19cc9 100644 --- a/quickpeep/src/bin/quickpeep.rs +++ b/quickpeep/src/bin/quickpeep.rs @@ -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")?, diff --git a/quickpeep/src/config.rs b/quickpeep/src/config.rs index 9c02d05..75adac3 100644 --- a/quickpeep/src/config.rs +++ b/quickpeep/src/config.rs @@ -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)>, } diff --git a/quickpeep/src/web/searcher.rs b/quickpeep/src/web/searcher.rs index 639f29e..47899b0 100644 --- a/quickpeep/src/web/searcher.rs +++ b/quickpeep/src/web/searcher.rs @@ -33,7 +33,7 @@ pub async fn search_root(Extension(web_config): Extension) -> 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(), })) } diff --git a/quickpeep/src/web/seed_collector.rs b/quickpeep/src/web/seed_collector.rs index 217e6cc..1921a08 100644 --- a/quickpeep/src/web/seed_collector.rs +++ b/quickpeep/src/web/seed_collector.rs @@ -37,13 +37,13 @@ pub async fn seed_collection_root( Extension(web_config): Extension, ) -> 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(), })) }