From 359c0133b8e3fbcd537c2f38b5b071f970cfa9bf Mon Sep 17 00:00:00 2001 From: Aravinth Manivannan Date: Thu, 23 Feb 2023 11:41:33 +0530 Subject: [PATCH] feat: import index from federating node --- federate/federate-core/Cargo.toml | 4 ++++ federate/federate-core/src/lib.rs | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/federate/federate-core/Cargo.toml b/federate/federate-core/Cargo.toml index 5301b54..d9d6a32 100644 --- a/federate/federate-core/Cargo.toml +++ b/federate/federate-core/Cargo.toml @@ -19,6 +19,10 @@ async-trait = "0.1.51" thiserror = "1.0.30" serde = { version = "1", features = ["derive"]} url = { version = "2.2.2", features = ["serde"] } +api_routes = { path = "../../api_routes/" } + +[dependencies.reqwest] +version = "0.11.10" [dependencies.db-core] path = "../../db/db-core" diff --git a/federate/federate-core/src/lib.rs b/federate/federate-core/src/lib.rs index 03ce45f..3d64afb 100644 --- a/federate/federate-core/src/lib.rs +++ b/federate/federate-core/src/lib.rs @@ -20,6 +20,7 @@ use std::path::PathBuf; use std::result::Result; use async_trait::async_trait; +use reqwest::Client; use url::Url; use db_core::prelude::*; @@ -27,6 +28,8 @@ use db_core::prelude::*; #[cfg(feature = "test")] pub mod tests; +pub use api_routes::*; + #[async_trait] pub trait Federate: Sync + Send { type Error: std::error::Error + std::fmt::Debug; @@ -79,6 +82,19 @@ pub trait Federate: Sync + Send { /// get latest tar ball async fn latest_tar(&self) -> Result; + + /// import archive from another Starchart instance + async fn import( + &self, + mut starchart_url: Url, + client: &Client, + db: &Box, + ) -> Result<(), Self::Error>; + + async fn latest_tar_json(&self) -> Result { + let latest = self.latest_tar().await?; + Ok(LatestResp { latest }) + } } pub fn get_hostname(url: &Url) -> &str {