From 9a67476c77926f5d817621be69b46c124f312ecc Mon Sep 17 00:00:00 2001 From: "benjamin.747" Date: Tue, 20 Aug 2024 11:34:53 +0800 Subject: [PATCH] add ztm alias to path mapping --- Cargo.toml | 1 + ceres/src/api_service/import_api_service.rs | 7 ----- ceres/src/api_service/mod.rs | 3 -- ceres/src/api_service/mono_api_service.rs | 9 ------ ceres/src/model/mod.rs | 1 - ceres/src/model/publish_path.rs | 21 -------------- gateway/Cargo.toml | 4 ++- gateway/src/api/mod.rs | 1 + gateway/src/api/model.rs | 22 ++++++++++++++ gateway/src/api/nostr_router.rs | 1 + gateway/src/api/ztm_router.rs | 32 +++++++++++---------- gateway/src/https_server.rs | 4 +-- gemini/src/http/handler.rs | 7 ++--- gemini/src/util.rs | 5 ++++ jupiter/callisto/src/lib.rs | 1 + jupiter/callisto/src/prelude.rs | 1 + jupiter/callisto/src/ztm_path_mapping.rs | 21 ++++++++++++++ jupiter/src/storage/git_db_storage.rs | 1 - jupiter/src/storage/ztm_storage.rs | 23 ++++++++++++++- lunar/src-tauri/src/main.rs | 12 ++++---- lunar/src/app/api/fetcher.ts | 19 ++++++++---- lunar/src/app/page.tsx | 23 +++++++++------ lunar/src/app/settings/page.tsx | 13 +++++---- lunar/src/app/tree/page.tsx | 6 ++-- lunar/src/components/CodeTable.tsx | 30 ++++++++++--------- mono/Cargo.toml | 2 +- mono/src/api/api_router.rs | 21 +------------- saturn/Cargo.toml | 2 +- sql/postgres/pg_20240205__init.sql | 10 +++++++ sql/sqlite/sqlite_20240711_init.sql | 9 ++++++ 30 files changed, 185 insertions(+), 127 deletions(-) delete mode 100644 ceres/src/model/publish_path.rs create mode 100644 gateway/src/api/model.rs create mode 100644 jupiter/callisto/src/ztm_path_mapping.rs diff --git a/Cargo.toml b/Cargo.toml index c7ec1f8b3..1d3740784 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/ceres/src/api_service/import_api_service.rs b/ceres/src/api_service/import_api_service.rs index 54d64948b..33a52b5b9 100644 --- a/ceres/src/api_service/import_api_service.rs +++ b/ceres/src/api_service/import_api_service.rs @@ -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)] @@ -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, MegaError> { self.context .services diff --git a/ceres/src/api_service/mod.rs b/ceres/src/api_service/mod.rs index abc0153eb..c03112d3f 100644 --- a/ceres/src/api_service/mod.rs +++ b/ceres/src/api_service/mod.rs @@ -18,7 +18,6 @@ use mercury::{ use crate::model::{ create_file::CreateFileInfo, - publish_path::PublishPathInfo, tree::{LatestCommitInfo, TreeBriefItem, TreeCommitItem, UserInfo}, }; @@ -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, MegaError>; fn strip_relative(&self, path: &Path) -> Result; diff --git a/ceres/src/api_service/mono_api_service.rs b/ceres/src/api_service/mono_api_service.rs index 3ff2f988d..be661b77c 100644 --- a/ceres/src/api_service/mono_api_service.rs +++ b/ceres/src/api_service/mono_api_service.rs @@ -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 { @@ -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, MegaError> { self.context .services diff --git a/ceres/src/model/mod.rs b/ceres/src/model/mod.rs index c07ca9398..e8e90291e 100644 --- a/ceres/src/model/mod.rs +++ b/ceres/src/model/mod.rs @@ -1,5 +1,4 @@ pub mod create_file; pub mod mr; -pub mod publish_path; pub mod query; pub mod tree; diff --git a/ceres/src/model/publish_path.rs b/ceres/src/model/publish_path.rs deleted file mode 100644 index 65143f5e0..000000000 --- a/ceres/src/model/publish_path.rs +++ /dev/null @@ -1,21 +0,0 @@ -use common::utils::generate_id; -use serde::{Deserialize, Serialize}; - -use crate::protocol::repo::Repo; - -#[derive(PartialEq, Eq, Debug, Clone, Default, Serialize, Deserialize)] -pub struct PublishPathInfo { - pub repo_name: String, - pub path: String, -} - -impl From for Repo { - fn from(value: PublishPathInfo) -> Self { - Self { - repo_id: generate_id(), - repo_path: value.path, - repo_name: value.repo_name, - is_monorepo: true, - } - } -} diff --git a/gateway/Cargo.toml b/gateway/Cargo.toml index f8e30346a..afdce54da 100644 --- a/gateway/Cargo.toml +++ b/gateway/Cargo.toml @@ -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 } @@ -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 } diff --git a/gateway/src/api/mod.rs b/gateway/src/api/mod.rs index 8d23ba70d..bab02a7ad 100644 --- a/gateway/src/api/mod.rs +++ b/gateway/src/api/mod.rs @@ -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 { diff --git a/gateway/src/api/model.rs b/gateway/src/api/model.rs new file mode 100644 index 000000000..20ee92822 --- /dev/null +++ b/gateway/src/api/model.rs @@ -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 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(), + } + } +} diff --git a/gateway/src/api/nostr_router.rs b/gateway/src/api/nostr_router.rs index f7fda8743..a2dd35f87 100644 --- a/gateway/src/api/nostr_router.rs +++ b/gateway/src/api/nostr_router.rs @@ -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, diff --git a/gateway/src/api/ztm_router.rs b/gateway/src/api/ztm_router.rs index 28d491f49..49f8d9b64 100644 --- a/gateway/src/api/ztm_router.rs +++ b/gateway/src/api/ztm_router.rs @@ -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 { 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>, state: State, + Json(json): Json, ) -> Result>, (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 => { @@ -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 { @@ -98,11 +101,10 @@ async fn repo_folk( Ok(Json(res)) } -async fn hello( +async fn peer_id( Query(_query): Query>, _state: State, ) -> Result>, (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)))) } diff --git a/gateway/src/https_server.rs b/gateway/src/https_server.rs index 37f6b2871..4c36f523b 100644 --- a/gateway/src/https_server.rs +++ b/gateway/src/https_server.rs @@ -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(), @@ -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( diff --git a/gemini/src/http/handler.rs b/gemini/src/http/handler.rs index b92ea88dd..4c3c6af03 100644 --- a/gemini/src/http/handler.rs +++ b/gemini/src/http/handler.rs @@ -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 { let url = format!("{bootstrap_node}/api/v1/repo_provide"); let git_model = context @@ -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, diff --git a/gemini/src/util.rs b/gemini/src/util.rs index 31ec5beb0..673964b9e 100644 --- a/gemini/src/util.rs +++ b/gemini/src/util.rs @@ -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()) diff --git a/jupiter/callisto/src/lib.rs b/jupiter/callisto/src/lib.rs index 310f38140..072b64b70 100644 --- a/jupiter/callisto/src/lib.rs +++ b/jupiter/callisto/src/lib.rs @@ -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; diff --git a/jupiter/callisto/src/prelude.rs b/jupiter/callisto/src/prelude.rs index 115efa574..1a998eef0 100644 --- a/jupiter/callisto/src/prelude.rs +++ b/jupiter/callisto/src/prelude.rs @@ -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; diff --git a/jupiter/callisto/src/ztm_path_mapping.rs b/jupiter/callisto/src/ztm_path_mapping.rs new file mode 100644 index 000000000..849ad15d9 --- /dev/null +++ b/jupiter/callisto/src/ztm_path_mapping.rs @@ -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 {} diff --git a/jupiter/src/storage/git_db_storage.rs b/jupiter/src/storage/git_db_storage.rs index ef79a2bd0..f341382a8 100644 --- a/jupiter/src/storage/git_db_storage.rs +++ b/jupiter/src/storage/git_db_storage.rs @@ -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()) diff --git a/jupiter/src/storage/ztm_storage.rs b/jupiter/src/storage/ztm_storage.rs index a1b0366eb..b0360845f 100644 --- a/jupiter/src/storage/ztm_storage.rs +++ b/jupiter/src/storage/ztm_storage.rs @@ -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}; @@ -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, MegaError> { + Ok(ztm_path_mapping::Entity::find() + .filter(ztm_path_mapping::Column::Alias.eq(alias)) + .one(self.get_connection()) + .await + .unwrap()) + } } diff --git a/lunar/src-tauri/src/main.rs b/lunar/src-tauri/src/main.rs index a6cea675d..9d11d9c34 100644 --- a/lunar/src-tauri/src/main.rs +++ b/lunar/src-tauri/src/main.rs @@ -11,6 +11,7 @@ use tauri::{Manager, State}; #[derive(Default)] struct ServiceState { child: Option, + with_relay: bool, } impl Drop for ServiceState { @@ -63,8 +64,10 @@ fn start_mega_service( } let args = if let Some(ref addr) = params.bootstrap_node { + service_state.with_relay = true; vec!["service", "http", "--bootstrap-node", addr] } else { + service_state.with_relay = false; vec!["service", "http"] }; let (mut rx, child) = Command::new_sidecar("mega") @@ -74,7 +77,6 @@ fn start_mega_service( .expect("Failed to spawn `Mega service`"); service_state.child = Some(child); - let cloned_state = Arc::clone(&state); // Sidecar output tauri::async_runtime::spawn(async move { while let Some(event) = rx.recv().await { @@ -95,9 +97,6 @@ fn start_mega_service( } else if let Some(signal) = payload.signal { eprintln!("Sidecar terminated by signal: {}", signal); } - // update ServiceState child - let mut service_state = cloned_state.lock().unwrap(); - service_state.child = None; break; } _ => {} @@ -112,6 +111,7 @@ fn stop_mega_service(state: State<'_, Arc>>) -> Result<(), S let mut service_state = state.lock().unwrap(); if let Some(child) = service_state.child.take() { child.kill().map_err(|e| e.to_string())?; + service_state.child = None; } else { println!("Mega Service is not running"); } @@ -129,9 +129,9 @@ fn restart_mega_service( } #[tauri::command] -async fn mega_service_status(state: State<'_, Arc>>) -> Result { +async fn mega_service_status(state: State<'_, Arc>>) -> Result<(bool, bool), String> { let service_state = state.lock().unwrap(); - Ok(service_state.child.is_some()) + Ok((service_state.child.is_some(), service_state.with_relay)) } fn main() { diff --git a/lunar/src/app/api/fetcher.ts b/lunar/src/app/api/fetcher.ts index f94f7dc52..95a1d126d 100644 --- a/lunar/src/app/api/fetcher.ts +++ b/lunar/src/app/api/fetcher.ts @@ -92,6 +92,16 @@ export function useRepoList() { } } +export function usePeerId() { + const { data, error, isLoading } = useSWR(`${endpoint}/api/v1/mega/ztm/peer_id`, fetcher, { + dedupingInterval: 60000, + }) + return { + peerId: data, + isLoading: isLoading, + isError: error, + } +} // export function usePublishRepo(path: string) { // const { data, error, isLoading } = useSWR(`${endpoint}/api/v1/mega/ztm/repo_provide?path=${path}`, fetcher) // return { @@ -119,18 +129,17 @@ export function useMegaStatus() { } // normal fetch -export async function requestPublishRepo(path) { - const response = await fetch(`${endpoint}/api/v1/mega/ztm/repo_provide?path=${path}`, { - method: 'GET', +export async function requestPublishRepo(data) { + const response = await fetch(`${endpoint}/api/v1/mega/ztm/repo_provide`, { + method: 'POST', headers: { 'Content-Type': 'application/json', }, + body: JSON.stringify(data), }); if (!response.ok) { throw new Error('Failed to publish repo'); } - - // 返回响应数据 return response.json(); } \ No newline at end of file diff --git a/lunar/src/app/page.tsx b/lunar/src/app/page.tsx index 0c687bbf5..1a508c11d 100644 --- a/lunar/src/app/page.tsx +++ b/lunar/src/app/page.tsx @@ -3,7 +3,7 @@ import { Flex, Layout, Skeleton, Alert } from "antd/lib"; import CodeTable from '@/components/CodeTable'; import MergeList from '@/components/MergeList'; -import { useTreeCommitInfo, useBlobContent, useMRList } from '@/app/api/fetcher'; +import { useTreeCommitInfo, useBlobContent, useMRList, useMegaStatus } from '@/app/api/fetcher'; const { Content } = Layout; @@ -39,23 +39,28 @@ export default function HomePage() { const { tree, isTreeLoading, isTreeError } = useTreeCommitInfo("/"); const { blob, isBlobLoading, isBlobError } = useBlobContent("/README.md"); const { mrList, isMRLoading, isMRError } = useMRList(""); + const { status, isLoading, isError } = useMegaStatus(); - if (isTreeLoading || isBlobLoading || isMRLoading) return ; + if (isTreeLoading || isBlobLoading || isMRLoading || isLoading) return ; return (
- + { + !status[1] && + + } + { { (tree && blob) && - + } diff --git a/lunar/src/app/settings/page.tsx b/lunar/src/app/settings/page.tsx index 529a3f9f5..4f23d07b2 100644 --- a/lunar/src/app/settings/page.tsx +++ b/lunar/src/app/settings/page.tsx @@ -6,7 +6,8 @@ import { Input } from '@/components/catalyst/input' import { Text } from '@/components/catalyst/text' import { invoke } from '@tauri-apps/api/tauri' import { useState } from 'react' -import { Button } from "antd"; +import { Button, Skeleton } from "antd"; +import { usePeerId } from '@/app/api/fetcher' interface MegaStartParams { bootstrap_node: string, @@ -16,8 +17,10 @@ export default function Settings() { const [loadings, setLoadings] = useState([]); const [params, setParams] = useState({ - bootstrap_node: "", + bootstrap_node: "http://34.84.172.121/relay", }); + const { peerId, isLoading, isError } = usePeerId(); + if (isLoading) return ; const enterLoading = (index: number) => { setLoadings((prevLoadings) => { @@ -69,7 +72,7 @@ export default function Settings() { + />
@@ -80,8 +83,8 @@ export default function Settings() { ZTM Agent Peer Id
-
diff --git a/lunar/src/app/tree/page.tsx b/lunar/src/app/tree/page.tsx index 407f4dd89..6caffeb22 100644 --- a/lunar/src/app/tree/page.tsx +++ b/lunar/src/app/tree/page.tsx @@ -3,7 +3,7 @@ import CodeTable from '@/components/CodeTable' import Bread from '@/components/BreadCrumb' import RepoTree from '@/components/RepoTree' -import { useBlobContent, useTreeCommitInfo } from '@/app/api/fetcher' +import { useBlobContent, useMegaStatus, useTreeCommitInfo } from '@/app/api/fetcher' import { useSearchParams } from 'next/navigation'; import { Skeleton, Flex, Layout } from "antd/lib"; import { Suspense } from 'react' @@ -21,6 +21,8 @@ function Tree() { const path = searchParams.get('path'); const { tree, isTreeLoading, isTreeError } = useTreeCommitInfo(path); const { blob, isBlobLoading, isBlobError } = useBlobContent(`${path}/README.md`); + const { status, isLoading, isError } = useMegaStatus(); + if (isTreeLoading || isBlobLoading) return ; const treeStyle = { @@ -55,7 +57,7 @@ function Tree() { - + ) diff --git a/lunar/src/components/CodeTable.tsx b/lunar/src/components/CodeTable.tsx index 568b02a2b..953e58cde 100644 --- a/lunar/src/components/CodeTable.tsx +++ b/lunar/src/components/CodeTable.tsx @@ -22,7 +22,7 @@ export interface DataType { date: number; } -const CodeTable = ({ directory, readmeContent }) => { +const CodeTable = ({ directory, readmeContent, with_ztm }) => { const router = useRouter(); const fileCodeContainerStyle = { width: '100%', @@ -78,8 +78,8 @@ const CodeTable = ({ directory, readmeContent }) => { key: 'action', render: (_, record) => ( - - + + ), }, @@ -127,7 +127,6 @@ const CodeTable = ({ directory, readmeContent }) => { }; const handleOk = async (filename) => { - var newPath = ''; if (!path) { newPath = `/${filename}`; @@ -135,12 +134,17 @@ const CodeTable = ({ directory, readmeContent }) => { newPath = `${path}/${filename}`; } setConfirmLoading(true); - // await requestPublishRepo(path) - setTimeout(() => { - console.log("publish path", newPath); - setOpen(false); - setConfirmLoading(false); - }, 2000); + await requestPublishRepo({ + "path": newPath, + "alias": filename, + }) + setOpen(false); + setConfirmLoading(false); + // setTimeout(() => { + // console.log("publish path", newPath); + // setOpen(false); + // setConfirmLoading(false); + // }, 2000); }; const handleCancel = () => { @@ -151,13 +155,13 @@ const CodeTable = ({ directory, readmeContent }) => {
handleOk(modalText)} + onOk={() => handleOk(modalText)} confirmLoading={confirmLoading} onCancel={handleCancel} > - + {readmeContent && (
diff --git a/mono/Cargo.toml b/mono/Cargo.toml index dd1404752..91f2393dc 100644 --- a/mono/Cargo.toml +++ b/mono/Cargo.toml @@ -20,7 +20,7 @@ taurus = { workspace = true } anyhow = { 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 } tracing-subscriber = { workspace = true } diff --git a/mono/src/api/api_router.rs b/mono/src/api/api_router.rs index 6d70c205a..5fc072e7b 100644 --- a/mono/src/api/api_router.rs +++ b/mono/src/api/api_router.rs @@ -8,7 +8,6 @@ use axum::{ use ceres::model::{ create_file::CreateFileInfo, - publish_path::PublishPathInfo, query::{BlobContentQuery, CodePreviewQuery}, tree::{LatestCommitInfo, TreeBriefItem, TreeCommitItem}, }; @@ -25,8 +24,7 @@ pub fn routers() -> Router { .route("/latest-commit", get(get_latest_commit)) .route("/tree/commit-info", get(get_tree_commit_info)) .route("/tree", get(get_tree_info)) - .route("/blob", get(get_blob_object)) - .route("/publish", post(publish_path_to_repo)); + .route("/blob", get(get_blob_object)); Router::new().merge(router).merge(mr_router::routers()) } @@ -117,20 +115,3 @@ async fn get_tree_commit_info( }; Ok(Json(res)) } - -async fn publish_path_to_repo( - state: State, - Json(json): Json, -) -> Result>, (StatusCode, String)> { - ApiRequestEvent::notify(ApiType::Publish, &state.0.context.config); - let res = state - .api_handler(json.path.clone().into()) - .await - .publish_path(json) - .await; - let res = match res { - Ok(_) => CommonResult::success(None), - Err(err) => CommonResult::failed(&err.to_string()), - }; - Ok(Json(res)) -} diff --git a/saturn/Cargo.toml b/saturn/Cargo.toml index 4a9befd10..ae6a376e8 100644 --- a/saturn/Cargo.toml +++ b/saturn/Cargo.toml @@ -12,4 +12,4 @@ tracing-subscriber = { workspace = true } thiserror = { workspace = true } itertools = "0.13.0" -cedar-policy = "3.2.1" +cedar-policy = "3.3.0" diff --git a/sql/postgres/pg_20240205__init.sql b/sql/postgres/pg_20240205__init.sql index 2fe2ce0c3..60742b02f 100644 --- a/sql/postgres/pg_20240205__init.sql +++ b/sql/postgres/pg_20240205__init.sql @@ -267,3 +267,13 @@ CREATE TABLE IF NOT EXISTS "mq_storage" ( "create_time" TIMESTAMP NOT NULL, "content" TEXT ); + + +CREATE TABLE IF NOT EXISTS "ztm_path_mapping" ( + "id" BIGINT PRIMARY KEY, + "alias" TEXT NOT NULL, + "repo_path" TEXT NOT NULL, + "created_at" TIMESTAMP NOT NULL, + "updated_at" TIMESTAMP NOT NULL, + CONSTRAINT uniq_alias UNIQUE (alias) +); \ No newline at end of file diff --git a/sql/sqlite/sqlite_20240711_init.sql b/sql/sqlite/sqlite_20240711_init.sql index 998a6fcff..3b23b132c 100644 --- a/sql/sqlite/sqlite_20240711_init.sql +++ b/sql/sqlite/sqlite_20240711_init.sql @@ -267,3 +267,12 @@ CREATE TABLE IF NOT EXISTS "mq_storage" ( "create_time" TIMESTAMP NOT NULL, "content" TEXT ); + +CREATE TABLE IF NOT EXISTS "ztm_path_mapping" ( + "id" BIGINT PRIMARY KEY, + "alias" TEXT NOT NULL, + "repo_path" TEXT NOT NULL, + "created_at" TIMESTAMP NOT NULL, + "updated_at" TIMESTAMP NOT NULL, + CONSTRAINT uniq_alias UNIQUE (alias) +); \ No newline at end of file