Skip to content

Commit

Permalink
Merge pull request #658 from wujian0327/main
Browse files Browse the repository at this point in the history
aries adds a new interface to save the relationship between lfs and peer
  • Loading branch information
genedna authored Oct 26, 2024
2 parents ee41c55 + 9465da7 commit e4412ff
Show file tree
Hide file tree
Showing 14 changed files with 796 additions and 234 deletions.
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

1 comment on commit e4412ff

@vercel
Copy link

@vercel vercel bot commented on e4412ff Oct 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

mega – ./

mega-git-main-gitmono.vercel.app
www.gitmega.dev
mega-gitmono.vercel.app
gitmega.dev

Please sign in to comment.