diff --git a/Cargo.toml b/Cargo.toml index f3e56de..2825b4a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,22 +7,38 @@ repository = "https://github.com/alemidev/fedicharter" readme = "README.md" edition = "2021" +[lib] +name = "fedicharter" +path = "src/lib.rs" + +[[bin]] +name = "fedicharter-cli" +path = "src/cli/main.rs" +required-features = ["cli"] + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] async-recursion = "1.0.5" -axum = "0.6.20" chrono = "0.4.31" -clap = { version = "4.4.6", features = ["derive"] } +thiserror = "1.0.49" derive_more = "0.99.17" -lazy_static = "1.4.0" -# nodeinfo = { git = "https://codeberg.org/thefederationinfo/nodeinfo-rs.git" } -reqwest = { version = "0.11.20", features = ["json"] } -sea-orm = { version = "0.12.3", features = ["runtime-tokio-native-tls", "sqlx-sqlite", "sqlx-postgres"] } serde = { version = "1.0.188", features = ["derive"] } serde_json = "1.0.107" -thiserror = "1.0.49" -tokio = { version = "1.32.0", features = ["full"] } -tracing = "0.1.37" -tracing-subscriber = "0.3.17" +tracing = "0.1.37" # TODO either this or log +log = "0.4.20" # TODO either this or tracing +#nodeinfo = { git = "https://codeberg.org/thefederationinfo/nodeinfo-rs.git" } +# async runtime and cli stuff +tokio = { version = "1.32.0", features = ["full"], optional = true } +tracing-subscriber = { version = "0.3.17", optional = true } +axum = { version = "0.6.20", optional = true } +reqwest = { version = "0.11.20", features = ["json"], optional = true } +sea-orm = { version = "0.12.3", features = ["runtime-tokio-native-tls", "sqlx-sqlite", "sqlx-postgres"], optional = true } +clap = { version = "4.4.6", features = ["derive"], optional = true } + + +[features] +default = ["web", "cli"] +db = ["dep:tokio", "dep:sea-orm", "dep:reqwest"] +cli = ["db", "dep:axum", "dep:tracing-subscriber", "dep:clap"] diff --git a/src/main.rs b/src/cli/main.rs similarity index 87% rename from src/main.rs rename to src/cli/main.rs index 9e7fb8f..f818a29 100644 --- a/src/main.rs +++ b/src/cli/main.rs @@ -1,19 +1,11 @@ use std::net::SocketAddr; -use crawl::collector::CollectorHandle; +use fedicharter::crawl::collector::CollectorHandle; use sea_orm::Database; use clap::{Parser, Subcommand}; use tracing_subscriber::{prelude::*, filter::{LevelFilter, filter_fn}}; -mod nodeinfo; // TODO this should me PRd into upstream - -mod entities; - -mod crawl; -mod serve; - - #[derive(Debug, Parser)] /// an API crawling akkoma bubble instances network and creating a map struct CliArgs { @@ -79,12 +71,12 @@ async fn main() { Some(host) => host.parse().expect("could not parse provided host"), None => SocketAddr::from(([127, 0, 0, 1], 18811)), }; - crate::serve::api_routes(addr, db).await; + fedicharter::serve::api_routes(addr, db).await; }, CliAction::Crawl { mode: CliCrawlMode::Bubble { domain } } => { let collector = CollectorHandle::new(db).await; - crate::crawl::bubble(&domain, collector).await.expect("network error wtf"); + fedicharter::crawl::bubble(&domain, collector).await.expect("network error wtf"); }, } } diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..fa7de5e --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,10 @@ +pub mod nodeinfo; // TODO this should me PRd into upstream + +#[cfg(feature = "db")] +pub mod entities; + +#[cfg(feature = "cli")] +pub mod crawl; + +#[cfg(feature = "cli")] +pub mod serve; diff --git a/src/nodeinfo/mod.rs b/src/nodeinfo/mod.rs index a5f661f..7b08ec1 100644 --- a/src/nodeinfo/mod.rs +++ b/src/nodeinfo/mod.rs @@ -1,4 +1,7 @@ pub mod model; + +#[cfg(feature = "cli")] pub mod fetcher; +#[cfg(feature = "cli")] pub use fetcher::fetch_node_info as fetch;