73 lines
2.2 KiB
Rust
73 lines
2.2 KiB
Rust
use crate::web::seed_collector::SeedTagColumn;
|
|
use anyhow::Context;
|
|
use quickpeep_index::backend::tantivy::TantivyBackend;
|
|
use quickpeep_index::backend::Backend;
|
|
use quickpeep_index::config::BackendConfig;
|
|
use serde::Deserialize;
|
|
use std::path::{Path, PathBuf};
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
pub struct SeedCollectionConfig {
|
|
pub column1: SeedTagColumn,
|
|
pub column2: SeedTagColumn,
|
|
pub column3: SeedTagColumn,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
pub struct WebConfig {
|
|
pub web: WebOnlyConfig,
|
|
pub index: IndexConfig,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
pub struct IndexConfig {
|
|
pub backend: BackendConfig,
|
|
pub icon_store: PathBuf,
|
|
}
|
|
|
|
#[derive(Debug, Clone, Deserialize)]
|
|
pub struct WebOnlyConfig {
|
|
pub seed_collection: SeedCollectionConfig,
|
|
pub sqlite_db_path: PathBuf,
|
|
/// Name, URL pairs
|
|
pub contact: Vec<(String, String)>,
|
|
|
|
/// URL prefix for QuickPeep. Should include protocol. No trailing slash.
|
|
/// Example: https://quickpeep.net
|
|
pub public_base: String,
|
|
}
|
|
|
|
impl WebConfig {
|
|
/// Loads a config at the specified path.
|
|
/// Will resolve all the paths in the IndexerConfig for you.
|
|
pub fn load(path: &Path) -> anyhow::Result<WebConfig> {
|
|
let config_dir = path.parent().context("Can't get parent of config file.")?;
|
|
let file_bytes = std::fs::read(path).context("Failed to read web config file")?;
|
|
let mut web_config: WebConfig =
|
|
ron::de::from_bytes(&file_bytes).context("Failed to parse web config")?;
|
|
|
|
match &mut web_config.index.backend {
|
|
BackendConfig::Tantivy(tantivy) => {
|
|
tantivy.index_dir = config_dir.join(&tantivy.index_dir);
|
|
}
|
|
BackendConfig::Meili(_) => {}
|
|
}
|
|
|
|
web_config.index.icon_store = config_dir.join(web_config.index.icon_store);
|
|
|
|
Ok(web_config)
|
|
}
|
|
|
|
pub fn open_indexer_backend(&self) -> anyhow::Result<Box<dyn Backend>> {
|
|
// TODO deduplicate with the indexer crate
|
|
match &self.index.backend {
|
|
BackendConfig::Tantivy(tantivy) => {
|
|
Ok(Box::new(TantivyBackend::open(&tantivy.index_dir)?))
|
|
}
|
|
BackendConfig::Meili(_) => {
|
|
todo!()
|
|
}
|
|
}
|
|
}
|
|
}
|