refactor: move modules into a library crate
Lets additional binaries share the labeler code. Adds a shared login() helper and Cities::iter/is_empty for use outside the crate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a7d410fd6d
commit
d1b01e180d
3 files changed
+35
-21
No files matched your search
@@ -75,6 +75,14 @@ impl Cities {
|
||||
self.keyed.len()
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.keyed.is_empty()
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = &City> {
|
||||
self.keyed.iter().map(|k| &k.city)
|
||||
}
|
||||
|
||||
pub fn get(&self, id: &str) -> Option<&City> {
|
||||
self.by_id.get(id).map(|&i| &self.keyed[i].city)
|
||||
}
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
pub mod cities;
|
||||
pub mod config;
|
||||
pub mod db;
|
||||
pub mod dms;
|
||||
pub mod labeler;
|
||||
pub mod labels;
|
||||
pub mod server;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use jacquard::client::{Agent, MemoryCredentialSession};
|
||||
use jacquard::types::string::Did;
|
||||
|
||||
/// Log in as the labeler account with an app password.
|
||||
pub async fn login(handle: &str, password: &str) -> Result<(Agent<MemoryCredentialSession>, Did)> {
|
||||
let (session, account) = MemoryCredentialSession::authenticated(handle, password, None, None)
|
||||
.await
|
||||
.with_context(|| format!("logging in as {handle}"))?;
|
||||
Ok((Agent::from(session), account.did))
|
||||
}
|
||||
+8
-21
@@ -1,38 +1,25 @@
|
||||
mod cities;
|
||||
mod config;
|
||||
mod db;
|
||||
mod dms;
|
||||
mod labeler;
|
||||
mod labels;
|
||||
mod server;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use jacquard::client::{Agent, MemoryCredentialSession};
|
||||
use cities_labeler::cities::Cities;
|
||||
use cities_labeler::config::Config;
|
||||
use cities_labeler::db::Db;
|
||||
use cities_labeler::dms::Dms;
|
||||
use cities_labeler::labeler::Labeler;
|
||||
use cities_labeler::{login, server};
|
||||
use k256::ecdsa::SigningKey;
|
||||
|
||||
use crate::cities::Cities;
|
||||
use crate::config::Config;
|
||||
use crate::db::Db;
|
||||
use crate::dms::Dms;
|
||||
use crate::labeler::Labeler;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
let config = Config::from_env()?;
|
||||
|
||||
let (session, account) =
|
||||
MemoryCredentialSession::authenticated(&config.handle, &config.app_password, None, None)
|
||||
.await
|
||||
.with_context(|| format!("logging in as {}", config.handle))?;
|
||||
let agent = Agent::from(session);
|
||||
let (agent, did) = login(&config.handle, &config.app_password).await?;
|
||||
|
||||
let key = SigningKey::from_slice(&hex::decode(&config.signing_key_hex)?)
|
||||
.context("SIGNING_KEY_HEX")?;
|
||||
let cities = Cities::load(&config.cities_path)?;
|
||||
let db = Arc::new(Db::open(&config.db_path)?);
|
||||
let labeler = Arc::new(Labeler::new(db, account.did, key));
|
||||
let labeler = Arc::new(Labeler::new(db, did, key));
|
||||
println!(
|
||||
"labeling as {}, loaded {} cities",
|
||||
labeler.did,
|
||||
|
||||
Reference in new issue
Block a user