Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 52 additions & 4 deletions aries/src/service/relay_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use axum::http::StatusCode;
use axum::response::IntoResponse;
use axum::routing::{get, post};
use axum::{Json, Router};
use callisto::{ztm_node, ztm_repo_info};
use callisto::{ztm_lfs_info, ztm_node, ztm_repo_info};
use clap::Parser;
use common::config::Config;
use gemini::ztm::hub::{LocalHub, ZTMUserPermit, ZTMCA};
use gemini::ztm::send_get_request_to_peer_by_tunnel;
use gemini::{Node, RelayGetParams, RelayResultRes, RepoInfo};
use gemini::{LFSInfo, LFSInfoPostBody, Node, RelayGetParams, RelayResultRes, RepoInfo};
use jupiter::context::Context;
use tower::ServiceBuilder;
use tower_http::cors::{Any, CorsLayer};
Expand Down Expand Up @@ -46,7 +46,7 @@ pub struct RelayOptions {
pub only_agent: bool,

#[arg(long, short)]
pub config: Option<String>
pub config: Option<String>,
}

#[derive(Clone)]
Expand Down Expand Up @@ -90,7 +90,9 @@ pub fn routers() -> Router<AppState> {
.route("/node_list", get(node_list))
.route("/repo_provide", post(repo_provide))
.route("/repo_list", get(repo_list))
.route("/test/send", get(send_message));
.route("/test/send", get(send_message))
.route("/lfs_share", post(lfs_share))
.route("/lfs_list", get(lfs_list));

Router::new()
.merge(router)
Expand Down Expand Up @@ -209,6 +211,52 @@ pub async fn repo_list(
Ok(Json(repo_info_list_result))
}

pub async fn lfs_share(
state: State<AppState>,
Json(lfs_info): Json<LFSInfoPostBody>,
) -> Result<Json<RelayResultRes>, (StatusCode, String)> {
let ztm_lfs_model: ztm_lfs_info::Model = lfs_info.into();
let storage = state.context.services.ztm_storage.clone();
match storage.insert_lfs_info(ztm_lfs_model).await {
Ok(_) => Ok(Json(RelayResultRes { success: true })),
Err(_) => Err((
StatusCode::INTERNAL_SERVER_ERROR,
"invalid paras".to_string(),
)),
}
}

pub async fn lfs_list(
Query(_query): Query<RelayGetParams>,
state: State<AppState>,
) -> Result<Json<Vec<LFSInfo>>, (StatusCode, String)> {
let storage = state.context.services.ztm_storage.clone();
let lfs_info_list: Vec<LFSInfo> = storage
.get_all_lfs_info()
.await
.unwrap()
.into_iter()
.map(|x| x.into())
.collect();
let nodelist: Vec<Node> = storage
.get_all_node()
.await
.unwrap()
.into_iter()
.map(|x| x.into())
.collect();
let mut lfs_info_list_result = vec![];
for mut lfs in lfs_info_list {
for node in &nodelist {
if lfs.peer_id == node.peer_id {
lfs.peer_online = node.online;
}
}
lfs_info_list_result.push(lfs.clone());
}
Ok(Json(lfs_info_list_result))
}

async fn send_message(
Query(query): Query<HashMap<String, String>>,
state: State<AppState>,
Expand Down
4 changes: 2 additions & 2 deletions common/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct ZtmOptions {
pub bootstrap_node: Option<String>,

#[arg(long, default_value_t = false)]
pub cache_repo: bool,
pub cache: bool,
}

#[derive(Deserialize, Debug)]
Expand Down Expand Up @@ -75,4 +75,4 @@ pub struct RequestParams<T> {
pub struct CommonPage<T> {
pub total: u64,
pub items: Vec<T>,
}
}
6 changes: 3 additions & 3 deletions gateway/src/https_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use axum::{http, Router};
use axum_server::tls_rustls::RustlsConfig;
use clap::Args;

use gemini::http::cache_repo::cache_public_repository;
use gemini::cache::cache_public_repo_and_lfs;
use tower::ServiceBuilder;
use tower_http::cors::{Any, CorsLayer};
use tower_http::decompression::RequestDecompressionLayer;
Expand Down Expand Up @@ -208,10 +208,10 @@ pub fn check_run_with_ztm(context: Context, ztm: ZtmOptions, http_port: u16) {
.await
});

if ztm.cache_repo {
if ztm.cache {
thread::sleep(time::Duration::from_secs(3));
tokio::spawn(async move {
cache_public_repository(bootstrap_node, context, ztm_agent).await
cache_public_repo_and_lfs(bootstrap_node, context, ztm_agent, http_port).await
});
}
}
Expand Down
Loading