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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ russh = "0.45.0"
russh-keys = "0.45.0"
axum = "0.7.5"
axum-extra = "0.9.3"
axum-server = "0.7"
tower-http = "0.5.2"
tower = "0.5.0"
hex = "0.4.3"
Expand Down
7 changes: 0 additions & 7 deletions ceres/src/api_service/import_api_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use mercury::internal::object::tree::TreeItem;

use crate::api_service::ApiHandler;
use crate::model::create_file::CreateFileInfo;
use crate::model::publish_path::PublishPathInfo;
use crate::protocol::repo::Repo;

#[derive(Clone)]
Expand All @@ -33,12 +32,6 @@ impl ApiHandler for ImportApiService {
));
}

async fn publish_path(&self, _: PublishPathInfo) -> Result<(), GitError> {
return Err(GitError::CustomError(
"Publish operation only support in mono directory".to_string(),
));
}

async fn get_raw_blob_by_hash(&self, hash: &str) -> Result<Option<raw_blob::Model>, MegaError> {
self.context
.services
Expand Down
3 changes: 0 additions & 3 deletions ceres/src/api_service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use mercury::{

use crate::model::{
create_file::CreateFileInfo,
publish_path::PublishPathInfo,
tree::{LatestCommitInfo, TreeBriefItem, TreeCommitItem, UserInfo},
};

Expand All @@ -29,8 +28,6 @@ pub mod mono_api_service;
pub trait ApiHandler: Send + Sync {
async fn create_monorepo_file(&self, file_info: CreateFileInfo) -> Result<(), GitError>;

async fn publish_path(&self, publish_info: PublishPathInfo) -> Result<(), GitError>;

async fn get_raw_blob_by_hash(&self, hash: &str) -> Result<Option<raw_blob::Model>, MegaError>;

fn strip_relative(&self, path: &Path) -> Result<PathBuf, GitError>;
Expand Down
9 changes: 0 additions & 9 deletions ceres/src/api_service/mono_api_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ use mercury::internal::object::tree::{Tree, TreeItem, TreeItemMode};
use crate::api_service::ApiHandler;
use crate::model::create_file::CreateFileInfo;
use crate::model::mr::{MRDetail, MrInfoItem};
use crate::model::publish_path::PublishPathInfo;
use crate::protocol::mr::MergeRequest;
use crate::protocol::repo::Repo;

#[derive(Clone)]
pub struct MonoApiService {
Expand Down Expand Up @@ -115,13 +113,6 @@ impl ApiHandler for MonoApiService {
Ok(())
}

async fn publish_path(&self, publish_info: PublishPathInfo) -> Result<(), GitError> {
let storage = self.context.services.git_db_storage.clone();
let repo: Repo = publish_info.into();
storage.save_git_repo(repo.clone().into()).await.unwrap();
Ok(())
}

async fn get_raw_blob_by_hash(&self, hash: &str) -> Result<Option<raw_blob::Model>, MegaError> {
self.context
.services
Expand Down
1 change: 0 additions & 1 deletion ceres/src/model/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub mod create_file;
pub mod mr;
pub mod publish_path;
pub mod query;
pub mod tree;
21 changes: 0 additions & 21 deletions ceres/src/model/publish_path.rs

This file was deleted.

4 changes: 3 additions & 1 deletion gateway/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ path = "src/lib.rs"
mono = { workspace = true }
common = { workspace = true }
jupiter = { workspace = true }
callisto = { workspace = true }
gemini = { workspace = true }
vault = { workspace = true }
taurus = { workspace = true }

axum = { workspace = true }
axum-server = { version = "0.7", features = ["tls-rustls"] }
axum-server = { workspace = true, features = ["tls-rustls"] }
tower = { workspace = true }
tracing = { workspace = true }
serde = { workspace = true }
Expand All @@ -32,3 +33,4 @@ tower-http = { workspace = true, features = [
tokio = { workspace = true, features = ["net"] }
reqwest = { workspace = true, features = ["json"] }
lazy_static = { workspace = true }
chrono = { workspace = true }
1 change: 1 addition & 0 deletions gateway/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use mono::api::MonoApiServiceState;
pub mod github_router;
pub mod nostr_router;
pub mod ztm_router;
mod model;

#[derive(Clone)]
pub struct MegaApiServiceState {
Expand Down
22 changes: 22 additions & 0 deletions gateway/src/api/model.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use serde::Deserialize;

use callisto::ztm_path_mapping;
use common::utils::generate_id;

#[derive(Debug, Deserialize, Clone)]
pub struct RepoProvideQuery {
pub alias: String,
pub path: String,
}

impl From<RepoProvideQuery> for ztm_path_mapping::Model {
fn from(value: RepoProvideQuery) -> Self {
Self {
id: generate_id(),
alias: value.alias,
repo_path: value.path,
created_at: chrono::Utc::now().naive_utc(),
updated_at: chrono::Utc::now().naive_utc(),
}
}
}
1 change: 1 addition & 0 deletions gateway/src/api/nostr_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ async fn recieve(

#[derive(Deserialize, Serialize, Debug, Clone)]
pub struct GitEventReq {
// TODO change path with alias
pub path: String,
pub action: String,
pub title: String,
Expand Down
32 changes: 17 additions & 15 deletions gateway/src/api/ztm_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,29 @@ use std::collections::HashMap;
use axum::{
extract::{Query, State},
http::StatusCode,
routing::get,
routing::{get, post},
Json, Router,
};

use callisto::ztm_path_mapping;
use common::model::CommonResult;
use gemini::nostr::subscribe_git_event;
use vault::get_peerid;

use crate::api::model::RepoProvideQuery;
use crate::api::MegaApiServiceState;

pub fn routers() -> Router<MegaApiServiceState> {
Router::new()
.route("/ztm/repo_provide", get(repo_provide))
.route("/ztm/repo_provide", post(repo_provide))
.route("/ztm/repo_fork", get(repo_folk))
.route("/ztm/hello", get(hello))
.route("/ztm/peer_id", get(peer_id))
}

async fn repo_provide(
Query(query): Query<HashMap<String, String>>,
state: State<MegaApiServiceState>,
Json(json): Json<RepoProvideQuery>,
) -> Result<Json<CommonResult<String>>, (StatusCode, String)> {
let path = match query.get("path") {
Some(p) => p,
None => {
return Err((StatusCode::BAD_REQUEST, String::from("Path not provide\n")));
}
};
let bootstrap_node = match state.ztm.bootstrap_node.clone() {
Some(b) => b.clone(),
None => {
Expand All @@ -39,11 +35,18 @@ async fn repo_provide(
));
}
};
let RepoProvideQuery { path, alias } = json.clone();
let context = state.inner.context.clone();
let model: ztm_path_mapping::Model = json.into();
match context.services.ztm_storage.save_alias_mapping(model.clone()).await {
Ok(_) => (),
Err(err) => return Err((StatusCode::BAD_REQUEST, err.to_string())),
}
let res = match gemini::http::handler::repo_provide(
state.port,
bootstrap_node,
state.inner.context.clone(),
path.to_string(),
path,
alias,
)
.await
{
Expand Down Expand Up @@ -98,11 +101,10 @@ async fn repo_folk(
Ok(Json(res))
}

async fn hello(
async fn peer_id(
Query(_query): Query<HashMap<String, String>>,
_state: State<MegaApiServiceState>,
) -> Result<Json<CommonResult<String>>, (StatusCode, String)> {
let (peer_id, _) = vault::init();
let msg = format!("hello from {peer_id}");
Ok(Json(CommonResult::success(Some(msg))))
Ok(Json(CommonResult::success(Some(peer_id))))
}
4 changes: 2 additions & 2 deletions gateway/src/https_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub async fn app(
common: common.clone(),
};

let mrga_api_state = MegaApiServiceState {
let mega_api_state = MegaApiServiceState {
inner: MonoApiServiceState {
context: context.clone(),
common: common.clone(),
Expand Down Expand Up @@ -159,7 +159,7 @@ pub async fn app(
)
.nest(
"/api/v1/mega",
mega_routers().with_state(mrga_api_state.clone()),
mega_routers().with_state(mega_api_state.clone()),
)
// Using Regular Expressions for Path Matching in Protocol
.route(
Expand Down
7 changes: 3 additions & 4 deletions gemini/src/http/handler.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use jupiter::context::Context;

use crate::{
util::{get_short_peer_id, repo_path_to_identifier},
util::{get_short_peer_id, repo_alias_to_identifier},
ztm::{agent::share_repo, create_tunnel},
RepoInfo,
};

pub async fn repo_provide(
port: u16,
bootstrap_node: String,
context: Context,
path: String,
alias: String,
) -> Result<String, String> {
let url = format!("{bootstrap_node}/api/v1/repo_provide");
let git_model = context
Expand Down Expand Up @@ -38,9 +38,8 @@ pub async fn repo_provide(
.unwrap();

let name = git_model.repo_name;
let repo_path = git_model.repo_path;
let (peer_id, _) = vault::init();
let identifier = repo_path_to_identifier(port, repo_path);
let identifier = repo_alias_to_identifier(alias);
let update_time = git_model.created_at.and_utc().timestamp();
let repo_info = RepoInfo {
name,
Expand Down
5 changes: 5 additions & 0 deletions gemini/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ pub async fn handle_response(
}
}

pub fn repo_alias_to_identifier( alias: String) -> String {
let (peer_id, _) = vault::init();
format!("p2p://{}/{alias}", peer_id.clone())
}

pub fn repo_path_to_identifier(http_port: u16, repo_path: String) -> String {
let (peer_id, _) = vault::init();
format!("p2p://{}/{http_port}{repo_path}.git", peer_id.clone())
Expand Down
1 change: 1 addition & 0 deletions jupiter/callisto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ pub mod raw_blob;
pub mod ztm_node;
pub mod ztm_nostr_event;
pub mod ztm_nostr_req;
pub mod ztm_path_mapping;
pub mod ztm_repo_info;
1 change: 1 addition & 0 deletions jupiter/callisto/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ pub use crate::mega_tag::Entity as MegaTag;
pub use crate::mega_tree::Entity as MegaTree;
pub use crate::raw_blob::Entity as RawBlob;
pub use crate::ztm_node::Entity as ZtmNode;
pub use crate::ztm_path_mapping::Entity as ZtmPathMapping;
pub use crate::ztm_repo_info::Entity as ZtmRepoInfo;
21 changes: 21 additions & 0 deletions jupiter/callisto/src/ztm_path_mapping.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.0

use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "ztm_path_mapping")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: i64,
#[sea_orm(column_type = "Text")]
pub alias: String,
#[sea_orm(column_type = "Text")]
pub repo_path: String,
pub created_at: DateTime,
pub updated_at: DateTime,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}
1 change: 0 additions & 1 deletion jupiter/src/storage/git_db_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ impl GitDbStorage {
}

pub async fn save_git_repo(&self, repo: git_repo::Model) -> Result<(), MegaError> {
// let model: git_repo::Model = repo.into();
let a_model = repo.into_active_model();
git_repo::Entity::insert(a_model)
.exec(self.get_connection())
Expand Down
23 changes: 22 additions & 1 deletion jupiter/src/storage/ztm_storage.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::Arc;

use callisto::{ztm_node, ztm_nostr_event, ztm_nostr_req, ztm_repo_info};
use callisto::{ztm_node, ztm_nostr_event, ztm_nostr_req, ztm_path_mapping, ztm_repo_info};
use common::errors::MegaError;
use sea_orm::InsertResult;
use sea_orm::{ColumnTrait, DatabaseConnection, EntityTrait, IntoActiveModel, QueryFilter, Set};
Expand Down Expand Up @@ -232,4 +232,25 @@ impl ZTMStorage {
.await
.unwrap())
}

pub async fn save_alias_mapping(
&self,
model: ztm_path_mapping::Model,
) -> Result<(), MegaError> {
ztm_path_mapping::Entity::insert(model.into_active_model())
.exec(self.get_connection())
.await?;
Ok(())
}

pub async fn get_path_from_alias(
&self,
alias: &str,
) -> Result<Option<ztm_path_mapping::Model>, MegaError> {
Ok(ztm_path_mapping::Entity::find()
.filter(ztm_path_mapping::Column::Alias.eq(alias))
.one(self.get_connection())
.await
.unwrap())
}
}
Loading