diff --git a/src/api/mod.rs b/src/api/mod.rs index 716da79..be67521 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -20,6 +20,7 @@ mod stream; mod xrpc; pub async fn serve(hydrant: Hydrant, port: u16) -> miette::Result<()> { + let blocks_available = hydrant.state.is_block_storage_enabled(); let app = Router::new() .route( "/", @@ -41,7 +42,7 @@ pub async fn serve(hydrant: Hydrant, port: u16) -> miette::Result<()> { #[cfg(feature = "indexer")] let app = app.nest("/stream", stream::router()); let app = app - .merge(xrpc::router()) + .merge(xrpc::router(blocks_available)) .merge(filter::router()) .merge(pds::router()) .merge(repos::router()) diff --git a/src/api/xrpc/mod.rs b/src/api/xrpc/mod.rs index 18dc7d7..b96146d 100644 --- a/src/api/xrpc/mod.rs +++ b/src/api/xrpc/mod.rs @@ -64,7 +64,7 @@ mod request_crawl; #[cfg(feature = "relay")] mod subscribe_repos; -pub fn router() -> Router { +pub fn router(blocks_available: bool) -> Router { let r = Router::new() .route(GetHostStatusRequest::PATH, get(get_host_status::handle)) .route(ListHostsRequest::PATH, get(list_hosts::handle)) @@ -74,16 +74,22 @@ pub fn router() -> Router { #[cfg(feature = "indexer")] let r = r - .route(GetRecordRequest::PATH, get(get_record::handle)) - .route(ListRecordsRequest::PATH, get(list_records::handle)) .route(CountRecords::PATH, get(count_records::handle)) - .route(GetRepoRequest::PATH, get(get_repo::handle)) .route(DescribeRepo::PATH, get(describe_repo::handle)) .route( AtprotoDescribeRepoRequest::PATH, get(com_atproto_describe_repo::handle), ); + #[cfg(feature = "indexer")] + let r = if blocks_available { + r.route(GetRecordRequest::PATH, get(get_record::handle)) + .route(ListRecordsRequest::PATH, get(list_records::handle)) + .route(GetRepoRequest::PATH, get(get_repo::handle)) + } else { + r + }; + #[cfg(feature = "relay")] let r = r .route(SubscribeReposEndpoint::PATH, get(subscribe_repos::handle)) diff --git a/src/control/repos/indexer.rs b/src/control/repos/indexer.rs index 3a4f3b0..81001e8 100644 --- a/src/control/repos/indexer.rs +++ b/src/control/repos/indexer.rs @@ -334,8 +334,8 @@ impl ReposControl { impl<'i> RepoHandle<'i> { /// gets a record from this repository. pub async fn get_record(&self, collection: &str, rkey: &str) -> Result> { - if self.state.only_index_links { - miette::bail!("block storage is disabled (HYDRANT_ONLY_INDEX_LINKS)"); + if !self.state.is_block_storage_enabled() { + miette::bail!("block storage is not available in this mode"); } let did = self.did.clone().into_static(); @@ -380,8 +380,8 @@ impl<'i> RepoHandle<'i> { reverse: bool, cursor: Option<&str>, ) -> Result { - if self.state.only_index_links { - miette::bail!("block storage is disabled (HYDRANT_ONLY_INDEX_LINKS)"); + if !self.state.is_block_storage_enabled() { + miette::bail!("block storage is not available in this mode"); } let did = self.did.clone().into_static(); @@ -486,8 +486,8 @@ impl<'i> RepoHandle<'i> { &self, ) -> Result> + Send + 'static>> { - if self.state.only_index_links { - miette::bail!("block storage is disabled (HYDRANT_ONLY_INDEX_LINKS)"); + if !self.state.is_block_storage_enabled() { + miette::bail!("block storage is not available in this mode"); } use iroh_car::{CarHeader, CarWriter}; use jacquard_repo::{BlockStore, MemoryBlockStore, Mst}; diff --git a/src/state.rs b/src/state.rs index ef2fdf0..796cbff 100644 --- a/src/state.rs +++ b/src/state.rs @@ -115,6 +115,10 @@ impl AppState { }) } + pub fn is_block_storage_enabled(&self) -> bool { + !self.ephemeral && !self.only_index_links + } + #[cfg(feature = "indexer")] pub fn notify_backfill(&self) { self.backfill_notify.notify_one();