feat: import index from federating node

This commit is contained in:
Aravinth Manivannan 2023-02-23 11:41:33 +05:30
parent 7b3bc8161e
commit 359c0133b8
Signed by: realaravinth
GPG key ID: AD9F0F08E855ED88
2 changed files with 20 additions and 0 deletions

View file

@ -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"

View file

@ -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<String, Self::Error>;
/// import archive from another Starchart instance
async fn import(
&self,
mut starchart_url: Url,
client: &Client,
db: &Box<dyn SCDatabase>,
) -> Result<(), Self::Error>;
async fn latest_tar_json(&self) -> Result<LatestResp, Self::Error> {
let latest = self.latest_tar().await?;
Ok(LatestResp { latest })
}
}
pub fn get_hostname(url: &Url) -> &str {