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
29 changes: 1 addition & 28 deletions ceres/src/model/mod.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,5 @@
use serde::{Deserialize, Serialize};

pub mod create_file;
pub mod mr;
pub mod publish_path;
pub mod query;
pub mod tree;
pub mod publish_path;

#[derive(PartialEq, Eq, Debug, Clone, Default, Serialize, Deserialize)]

pub struct CommonResult<T> {
pub req_result: bool,
pub data: Option<T>,
pub err_message: String,
}

impl<T> CommonResult<T> {
pub fn success(data: Option<T>) -> Self {
CommonResult {
req_result: true,
data,
err_message: "".to_owned(),
}
}
pub fn failed(err_message: &str) -> Self {
CommonResult {
req_result: false,
data: None,
err_message: err_message.to_string(),
}
}
}
17 changes: 11 additions & 6 deletions common/src/enums.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
use clap::ValueEnum;
// src/enums.rs

#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Debug)]
pub enum DataSource {
Mysql,
Postgres,
}
//! This file is used to share enums across different modules.
//!
//! By defining enums in a separate file, we can easily import and use them
//! in multiple modules within the project. This promotes code reuse and
//! consistency, especially when multiple modules need to work with the same
//! set of enum variants.


use clap::ValueEnum;

/// An enum representing different ZTM types.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Debug)]
pub enum ZtmType {
Agent,
Expand Down
26 changes: 25 additions & 1 deletion common/src/model.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clap::Args;
use serde::Deserialize;
use serde::{Deserialize, Serialize};

use crate::enums::ZtmType;

Expand Down Expand Up @@ -38,3 +38,27 @@ pub struct GetParams {
pub identifier: Option<String>,
pub port: Option<u16>,
}

#[derive(PartialEq, Eq, Debug, Clone, Default, Serialize, Deserialize)]
pub struct CommonResult<T> {
pub req_result: bool,
pub data: Option<T>,
pub err_message: String,
}

impl<T> CommonResult<T> {
pub fn success(data: Option<T>) -> Self {
CommonResult {
req_result: true,
data,
err_message: "".to_owned(),
}
}
pub fn failed(err_message: &str) -> Self {
CommonResult {
req_result: false,
data: None,
err_message: err_message.to_string(),
}
}
}
11 changes: 8 additions & 3 deletions gateway/src/api/api_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ use axum::{
Json, Router,
};

use crate::api::mr_router;
use crate::api::ApiServiceState;
use ceres::model::{
create_file::CreateFileInfo, publish_path::PublishPathInfo, query::{BlobContentQuery, CodePreviewQuery}, tree::{LatestCommitInfo, TreeBriefItem, TreeCommitItem}, CommonResult
create_file::CreateFileInfo,
publish_path::PublishPathInfo,
query::{BlobContentQuery, CodePreviewQuery},
tree::{LatestCommitInfo, TreeBriefItem, TreeCommitItem},
};
use common::model::CommonResult;

use crate::api::mr_router;
use crate::api::ApiServiceState;

pub fn routers() -> Router<ApiServiceState> {
let router = Router::new()
Expand Down
7 changes: 3 additions & 4 deletions gateway/src/api/mr_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ use axum::{
Json, Router,
};

use ceres::model::mr::{MRDetail, MrInfoItem};
use common::model::CommonResult;

use crate::api::ApiServiceState;
use ceres::model::{
mr::{MRDetail, MrInfoItem},
CommonResult,
};

pub fn routers() -> Router<ApiServiceState> {
Router::new()
Expand Down
12 changes: 8 additions & 4 deletions gemini/src/http/handler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use axum::{body::Body, http::Response};
use common::model::GetParams;
use common::model::{CommonResult, GetParams};
use jupiter::context::Context;
use reqwest::StatusCode;
use venus::import_repo::repo::Repo;
Expand Down Expand Up @@ -34,7 +34,7 @@ pub async fn repo_provide(
let git_model = context
.services
.git_db_storage
.find_git_repo_by_path(path.as_str())
.find_git_repo_exact_match(path.as_str())
.await;

let git_model = match git_model {
Expand Down Expand Up @@ -163,8 +163,12 @@ pub async fn repo_folk(
return Err((StatusCode::INTERNAL_SERVER_ERROR, s));
}
}
let msg = format!("Success, you can try to clone the repo like this:\ngit clone http://localhost:{port}/{git_path}");
Ok(Response::builder().body(Body::from(msg)).unwrap())
let msg = format!("git clone http://localhost:{port}/{git_path}");
let json_string = serde_json::to_string(&CommonResult::success(Some(msg))).unwrap();
Ok(Response::builder()
.header("Content-Type", "application/json")
.body(Body::from(json_string))
.unwrap())
}

pub fn get_peer_id_from_identifier(identifier: String) -> Result<String, String> {
Expand Down
5 changes: 2 additions & 3 deletions gemini/src/ztm/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::{

use axum::async_trait;
use common::config::Config;
use jupiter::context::Context;
use reqwest::{header::CONTENT_TYPE, Client};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -370,12 +369,12 @@ impl ZTMAgent for LocalZTMAgent {
}
pub async fn run_ztm_client(
bootstrap_node: String,
config: Config,
_config: Config,
peer_id: String,
agent: LocalZTMAgent,
) {
let name = peer_id.clone();
let _context = Context::new(config.clone()).await;
// let _context = Context::new(config.clone()).await;

// let local_permit_option = read_secret(peer_id.as_str()).unwrap();
// let permit: ZTMUserPermit = match local_permit_option {
Expand Down
10 changes: 0 additions & 10 deletions jupiter/src/storage/git_db_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,16 +219,6 @@ impl GitDbStorage {
Ok(result)
}

pub async fn find_git_repo_by_path(
&self,
repo_path: &str,
) -> Result<Option<git_repo::Model>, MegaError> {
let query = git_repo::Entity::find().filter(git_repo::Column::RepoPath.eq(repo_path));
tracing::debug!("{}", query.build(DbBackend::Postgres).to_string());
let result = query.one(self.get_connection()).await?;
Ok(result)
}

pub async fn save_git_repo(&self, repo: Repo) -> Result<(), MegaError> {
let model: git_repo::Model = repo.into();
let a_model = model.into_active_model();
Expand Down
2 changes: 2 additions & 0 deletions lunar/.env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
RELAY_API_URL=http://34.84.172.121
MEGA_API_URL=http://localhost:8000
1 change: 1 addition & 0 deletions lunar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@tailwindcss/forms": "^0.5.7",
"@tauri-apps/api": "^1.6.0",
"clsx": "^2.1.1",
"date-fns": "^3.6.0",
"framer-motion": "^11.3.2",
"next": "14.2.3",
"react": "^18",
Expand Down
2 changes: 1 addition & 1 deletion lunar/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn hello_string(name: &str) -> String {
}

fn start_mega() {
let args_str = "service http".to_string();
let args_str = "service http --ztm agent --bootstrap-node http://34.84.172.121/relay".to_string();
let args = args_str.split(' ').collect();
mega::cli::parse(Some(args)).expect("failed to start mega");
}
Expand Down
16 changes: 16 additions & 0 deletions lunar/src/app/api/relay/repo_fork/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const revalidate = 0

import { NextRequest } from "next/server";

const endpoint = process.env.MEGA_API_URL;

export async function GET(request: NextRequest) {
const searchParams = request.nextUrl.searchParams
const identifier = searchParams.get('identifier')
const port = searchParams.get('port')
const res = await fetch(`${endpoint}/api/v1/ztm/repo_folk?identifier=${identifier}&port=${port}`, {
})
const data = await res.json()

return Response.json({ data })
}
10 changes: 10 additions & 0 deletions lunar/src/app/api/relay/repo_list/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const revalidate = 0

const endpoint = process.env.RELAY_API_URL;

export async function GET(request: Request, ) {
const res = await fetch(`${endpoint}/relay/repo_list`, {
})
const data = await res.json()
return Response.json({ data })
}
111 changes: 23 additions & 88 deletions lunar/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,99 +1,34 @@
'use client'

import React from 'react'
import { Space, Table, Tag } from 'antd'
import type { TableProps } from 'antd'
import HelloRust from '@/components/catalyst/hello'
import { GetResult } from '../../../moon/src/components/ApiResult'
import React, { useEffect, useState } from 'react'
import DataList from '@/components/DataList'

interface DataType {
key: string
name: string
age: number
address: string
tags: string[]
}

const columns: TableProps<DataType>['columns'] = [
{
title: 'Name',
dataIndex: 'name',
key: 'name',
render: (text) => <a>{text}</a>,
},
{
title: 'Age',
dataIndex: 'age',
key: 'age',
},
{
title: 'Address',
dataIndex: 'address',
key: 'address',
},
{
title: 'Tags',
key: 'tags',
dataIndex: 'tags',
render: (_, { tags }) => (
<>
{tags.map((tag) => {
let color = tag.length > 5 ? 'geekblue' : 'green'
if (tag === 'loser') {
color = 'volcano'
}
return (
<Tag color={color} key={tag}>
{tag.toUpperCase()}
</Tag>
)
})}
</>
),
},
{
title: 'Action',
key: 'action',
render: (_, record) => (
<Space size="middle">
<a>Invite {record.name}</a>
<a>Delete</a>
</Space>
),
},
]
export default function HomePage() {
const [repo_list, setRepoList] = useState([]);

const data: DataType[] = [
{
key: '1',
name: 'John Brown',
age: 32,
address: 'New York No. 1 Lake Park',
tags: ['nice', 'developer'],
},
{
key: '2',
name: 'Jim Green',
age: 42,
address: 'London No. 1 Lake Park',
tags: ['loser'],
},
{
key: '3',
name: 'Joe Black',
age: 32,
address: 'Sydney No. 1 Lake Park',
tags: ['cool', 'teacher'],
},
]
useEffect(() => {
const fetchData = async () => {
try {
let repo_list = await getRepoList();
setRepoList(repo_list);
} catch (error) {
console.error('Error fetching data:', error);
}
};
fetchData();
}, []);

export default function HomePage() {
return (
<div>
<Table columns={columns} dataSource={data} />
<HelloRust />
{/* ---- */}
<GetResult host="http://127.0.0.1:8000/api/v1/tree" />
<DataList data={repo_list} />
</div>
)
}

async function getRepoList() {
const res = await fetch(`api/relay/repo_list`);
const response = await res.json();
const repo_list = response.data;
return repo_list
}
Loading