From ac40e8a659f23c69b4f12e754fad49fa93f66d85 Mon Sep 17 00:00:00 2001 From: Debjit Date: Tue, 31 Mar 2026 19:58:53 +0530 Subject: [PATCH] feat(client): add era type override functionality to EraClient --- crates/era-downloader/src/client.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/crates/era-downloader/src/client.rs b/crates/era-downloader/src/client.rs index 1c85dfd7216..2bb1ea034c8 100644 --- a/crates/era-downloader/src/client.rs +++ b/crates/era-downloader/src/client.rs @@ -52,11 +52,20 @@ impl EraClient { const CHECKSUMS: &'static str = "checksums.txt"; /// Constructs [`EraClient`] using `client` to download from `url` into `folder`. + /// + /// The file type is auto-detected from the URL. Use + /// [`with_era_type`](Self::with_era_type) to override. pub fn new(client: Http, url: Url, folder: impl Into>) -> Self { let era_type = EraFileType::from_url(url.as_str()); Self { client, url, folder: folder.into(), era_type } } + /// Override the auto-detected [`EraFileType`]. + pub const fn with_era_type(mut self, era_type: EraFileType) -> Self { + self.era_type = era_type; + self + } + /// Performs a GET request on `url` and stores the response body into a file located within /// the `folder`. pub async fn download_to_file(&mut self, url: impl IntoUrl) -> eyre::Result> { @@ -367,4 +376,19 @@ mod tests { assert_eq!(actual_number, expected_number); } + + #[test] + fn test_with_era_type_overrides_auto_detection() { + // URL without "era1" auto-detects as Era + let client = EraClient::new( + Client::new(), + Url::from_str("https://example.com/").unwrap(), + PathBuf::new(), + ); + assert_eq!(client.era_type, EraFileType::Era); + + // with_era_type overrides to Era1 + let client = client.with_era_type(EraFileType::Era1); + assert_eq!(client.era_type, EraFileType::Era1); + } }