at protocol indexer with flexible filtering, xrpc queries, and a cursor-backed event stream, built on fjall
at-protocol
atproto
indexer
rust
fjall
1use miette::{IntoDiagnostic, Result};
2use smol_str::SmolStr;
3use std::env;
4use std::path::PathBuf;
5use std::time::Duration;
6use url::Url;
7
8#[derive(Debug, Clone)]
9pub struct Config {
10 pub database_path: PathBuf,
11 pub relay_host: SmolStr,
12 pub plc_url: Url,
13 pub full_network: bool,
14 pub cursor_save_interval: Duration,
15 pub repo_fetch_timeout: Duration,
16 pub log_level: SmolStr,
17 pub api_port: u16,
18 pub cache_size: u64,
19 pub backfill_concurrency_limit: usize,
20 pub disable_lz4_compression: bool,
21 pub debug_port: u16,
22 pub enable_debug: bool,
23}
24
25impl Config {
26 pub fn from_env() -> Result<Self> {
27 let database_path = env::var("HYDRANT_DATABASE_PATH")
28 .unwrap_or_else(|_| "./hydrant.db".to_string())
29 .into();
30
31 let relay_host = env::var("HYDRANT_RELAY_HOST")
32 .unwrap_or_else(|_| "wss://relay.fire.hose.cam".to_string())
33 .into();
34
35 let plc_url = env::var("HYDRANT_PLC_URL")
36 .unwrap_or_else(|_| "https://plc.wtf".to_string())
37 .parse()
38 .into_diagnostic()?;
39
40 let full_network = env::var("HYDRANT_FULL_NETWORK")
41 .map(|v| v == "true")
42 .unwrap_or(false);
43
44 let cursor_save_interval = env::var("HYDRANT_CURSOR_SAVE_INTERVAL")
45 .ok()
46 .and_then(|s| humantime::parse_duration(&s).ok())
47 .unwrap_or(Duration::from_secs(10));
48
49 let repo_fetch_timeout = env::var("HYDRANT_REPO_FETCH_TIMEOUT")
50 .ok()
51 .and_then(|s| humantime::parse_duration(&s).ok())
52 .unwrap_or(Duration::from_secs(300));
53
54 let log_level = env::var("HYDRANT_LOG_LEVEL")
55 .unwrap_or_else(|_| "info".to_string())
56 .into();
57
58 let api_port = env::var("HYDRANT_API_PORT")
59 .ok()
60 .and_then(|s| s.parse().ok())
61 .unwrap_or(3000);
62
63 let cache_size = env::var("HYDRANT_CACHE_SIZE")
64 .ok()
65 .and_then(|s| s.parse().ok())
66 .unwrap_or(256);
67
68 let backfill_concurrency_limit = env::var("HYDRANT_BACKFILL_CONCURRENCY_LIMIT")
69 .ok()
70 .and_then(|s| s.parse().ok())
71 .unwrap_or(32);
72
73 let disable_lz4_compression = env::var("HYDRANT_NO_LZ4_COMPRESSION")
74 .map(|v| v == "true")
75 .unwrap_or(false);
76
77 let debug_port = env::var("HYDRANT_DEBUG_PORT")
78 .ok()
79 .and_then(|s| s.parse().ok())
80 .unwrap_or(3001);
81
82 let enable_debug = env::var("HYDRANT_ENABLE_DEBUG")
83 .map(|v| v == "true")
84 .unwrap_or(false);
85
86 Ok(Self {
87 database_path,
88 relay_host,
89 plc_url,
90 full_network,
91 cursor_save_interval,
92 repo_fetch_timeout,
93 log_level,
94 api_port,
95 cache_size,
96 backfill_concurrency_limit,
97 disable_lz4_compression,
98 debug_port,
99 enable_debug,
100 })
101 }
102}