Skip to content

add repo publish api and tree, blob page #510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 15, 2024
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
6 changes: 3 additions & 3 deletions gateway/src/api/ztm_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::api::MegaApiServiceState;
pub fn routers() -> Router<MegaApiServiceState> {
Router::new()
.route("/ztm/repo_provide", get(repo_provide))
.route("/ztm/repo_folk", get(repo_folk))
.route("/ztm/repo_fork", get(repo_fork))
}

async fn repo_provide(
Expand Down Expand Up @@ -50,7 +50,7 @@ async fn repo_provide(
Ok(Json(res))
}

async fn repo_folk(
async fn repo_fork(
Query(query): Query<HashMap<String, String>>,
state: State<MegaApiServiceState>,
) -> Result<Json<CommonResult<String>>, (StatusCode, String)> {
Expand All @@ -76,7 +76,7 @@ async fn repo_folk(
}
};

let res = gemini::http::handler::repo_folk(
let res = gemini::http::handler::repo_fork(
state.ztm.ztm_agent_port,
identifier.to_string(),
local_port,
Expand Down
2 changes: 1 addition & 1 deletion gemini/src/http/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub async fn repo_provide(
Ok("success".to_string())
}

pub async fn repo_folk(
pub async fn repo_fork(
ztm_agent_port: u16,
identifier: String,
local_port: u16,
Expand Down
6 changes: 0 additions & 6 deletions jupiter/src/storage/git_db_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,6 @@ impl GitDbStorage {
.one(self.get_connection())
.await?;
Ok(result)
// if let Some(model) = result {
// let refs: Refs = model.into();
// Ok(Some(refs))
// } else {
// Ok(None)
// }
}

pub async fn default_branch_exist(&self, repo_id: i64) -> Result<bool, MegaError> {
Expand Down
8 changes: 6 additions & 2 deletions lunar/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
"next": "14.2.3",
"react": "^18",
"react-dom": "^18",
"swr": "^2.2.5"
"swr": "^2.2.5",
"github-markdown-css": "^5.6.1",
"react-markdown": "^9.0.1",
"prism-react-renderer": "^2.3.1"

},
"devDependencies": {
"@tauri-apps/cli": "^1.6.0",
Expand All @@ -35,4 +39,4 @@
"postcss": "^8.4.40",
"typescript": "^5.5.4"
}
}
}
52 changes: 48 additions & 4 deletions lunar/src/app/api/fetcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import useSWR from "swr";
import useSWR, { Fetcher } from "swr";
import { invoke } from '@tauri-apps/api/tauri';

const endpoint = process.env.NEXT_PUBLIC_API_URL;
const relay = process.env.NEXT_PUBLIC_RELAY_API_URL;
Expand Down Expand Up @@ -26,8 +27,8 @@ const fetcher = async url => {


export function useTreeCommitInfo(path) {
const { data, error, isLoading } = useSWR(`${endpoint}/api/v1/tree/commit-info?path=${path}`, fetcher, {
dedupingInterval: 60000,
const { data, error, isLoading } = useSWR(`${endpoint}/api/v1/mono/tree/commit-info?path=${path}`, fetcher, {
dedupingInterval: 1000,
})
return {
tree: data,
Expand All @@ -37,7 +38,7 @@ export function useTreeCommitInfo(path) {
}

export function useBlobContent(path) {
const { data, error, isLoading } = useSWR(`${endpoint}/api/v1/blob?path=${path}`, fetcher, {
const { data, error, isLoading } = useSWR(`${endpoint}/api/v1/mono/blob?path=${path}`, fetcher, {
dedupingInterval: 60000,
})
return {
Expand All @@ -57,3 +58,46 @@ export function useRepoList() {
isError: error,
}
}

// export function usePublishRepo(path: string) {
// const { data, error, isLoading } = useSWR(`${endpoint}/api/v1/mega/ztm/repo_provide?path=${path}`, fetcher)
// return {
// data: data,
// isLoading,
// isError: error,
// }
// }

export const tauriFetcher: Fetcher<any, [string, { [key: string]: any }]> = ([key, args]) => {
return invoke(key, args);
};

export function useMegaStatus() {
const { data, error, isLoading } = useSWR(
['mega_service_status', {}],
tauriFetcher
);

return {
status: data,
isLoading,
isError: error,
};
}

// normal fetch
export async function requestPublishRepo(path) {
const response = await fetch(`${endpoint}/api/v1/mega/ztm/repo_provide?path=${path}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});

if (!response.ok) {
throw new Error('Failed to publish repo');
}

// 返回响应数据
return response.json();
}
2 changes: 1 addition & 1 deletion lunar/src/app/api/relay/repo_fork/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ 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 res = await fetch(`${endpoint}/api/v1/mega/ztm/repo_fork?identifier=${identifier}&port=${port}`, {
})
const data = await res.json()

Expand Down
1 change: 0 additions & 1 deletion lunar/src/app/application-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import {
HomeIcon,
QuestionMarkCircleIcon,
SparklesIcon,
Square2StackIcon,
TicketIcon,
ChatBubbleLeftRightIcon,
CodeBracketSquareIcon,
Expand Down
22 changes: 22 additions & 0 deletions lunar/src/app/blob/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use client'
import CodeContent from '@/components/CodeContent';
import Bread from '@/components/BreadCrumb';
import { useSearchParams } from 'next/navigation';
import { useBlobContent } from '../api/fetcher';
import { Skeleton } from "antd/lib";


export default function BlobPage() {
const searchParams = useSearchParams();
const path = searchParams.get('path');

const { blob, isBlobLoading, isBlobError } = useBlobContent(`${path}`);
if (isBlobLoading) return <Skeleton />;

return (
<div>
<Bread path={path} />
<CodeContent fileContent={blob.data} />
</div>
)
}
65 changes: 41 additions & 24 deletions lunar/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use client'

import { Flex, Layout } from 'antd';
import { Skeleton } from "antd";
import CodeTable from '../../../moon/src/components/CodeTable';
import MergeList from '../../../moon/src/components/MergeList';
import { useTreeCommitInfo, useBlobContent } from '@/app/api/fetcher';
import { Skeleton, Button, Result } from "antd/lib";
import CodeTable from '@/components/CodeTable';
import MergeList from '@/components/MergeList';
import { useTreeCommitInfo, useBlobContent, useMegaStatus } from '@/app/api/fetcher';

const { Content } = Layout;

Expand All @@ -22,6 +22,7 @@ const layoutStyle = {
overflow: 'hidden',
width: 'calc(50% - 8px)',
maxWidth: 'calc(50% - 8px)',
background: '#fff'
};

const mrList = [
Expand Down Expand Up @@ -51,27 +52,43 @@ const mrList = [
export default function HomePage() {
const { tree, isTreeLoading, isTreeError } = useTreeCommitInfo("/");
const { blob, isBlobLoading, isBlobError } = useBlobContent("/README.md");
const { status, isLoading, isError } = useMegaStatus();

if (isTreeLoading || isBlobLoading || isLoading) return <Skeleton />;

return (
<Flex gap="middle" wrap>
<Layout style={layoutStyle}>
{(isTreeLoading || isBlobLoading) &&
<Skeleton />
}
{
(tree && blob) &&
<CodeTable directory={tree.data} readmeContent={blob.data} treeIsShow={false} />
}
</Layout>
<Layout style={layoutStyle}>
{(isTreeLoading || isBlobLoading) &&
<Skeleton />
}
{(!isTreeLoading && !isBlobLoading) &&
<MergeList mrList={mrList} />
}
{/* <Content style={contentStyle}></Content> */}
</Layout>
</Flex>
<div>
{!status &&
< Result
status="warning"
title="Set relay server address first to start mega server"
extra={
<Button type="primary" key="setting" href='/settings'>
Go Setting
</Button>
}
/>
}
{
status &&
<Flex gap="middle" wrap>
<Layout style={layoutStyle}>
{
(tree && blob) &&
<CodeTable directory={tree.data} readmeContent={blob.data} />
}
</Layout>
<Layout style={layoutStyle}>
{(isTreeLoading || isBlobLoading) &&
<Skeleton />
}
{(!isTreeLoading && !isBlobLoading) &&
<MergeList mrList={mrList} />
}
{/* <Content style={contentStyle}></Content> */}
</Layout>
</Flex>
}
</div>
)
}
54 changes: 54 additions & 0 deletions lunar/src/app/tree/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use client'

import CodeTable from '@/components/CodeTable'
import Bread from '@/components/BreadCrumb'
import RepoTree from '@/components/RepoTree'
import { useBlobContent, useTreeCommitInfo } from '@/app/api/fetcher'
import { useSearchParams } from 'next/navigation';
import { Skeleton, Flex, Layout } from "antd/lib";


export default function Page() {
const searchParams = useSearchParams();
const path = searchParams.get('path');
const { tree, isTreeLoading, isTreeError } = useTreeCommitInfo(path);
const { blob, isBlobLoading, isBlobError } = useBlobContent(`${path}/README.md`);
if (isTreeLoading || isBlobLoading) return <Skeleton />;

const treeStyle = {
borderRadius: 8,
overflow: 'hidden',
width: 'calc(20% - 8px)',
maxWidth: 'calc(20% - 8px)',
background: '#fff',
};

const codeStyle = {
borderRadius: 8,
overflow: 'hidden',
width: 'calc(80% - 8px)',
background: '#fff',
};

const breadStyle = {
minHeight: 30,
borderRadius: 8,
overflow: 'hidden',
width: 'calc(100% - 8px)',
background: '#fff',
};

return (
<Flex gap="middle" wrap>
<Layout style={breadStyle}>
<Bread path={path} />
</Layout>
<Layout style={treeStyle}>
<RepoTree directory={tree.data} />
</Layout>
<Layout style={codeStyle}>
<CodeTable directory={tree.data} readmeContent={blob.data} />
</Layout>
</Flex>
);
}
5 changes: 5 additions & 0 deletions lunar/src/components/BreadCrumb.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.breadCrumb {
width: 80%;
margin-left: 18%;
margin-top: 20px;
}
32 changes: 32 additions & 0 deletions lunar/src/components/BreadCrumb.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'github-markdown-css/github-markdown-light.css'
import { useRouter } from 'next/navigation'
import { Breadcrumb } from 'antd/lib'
import styles from './BreadCrumb.module.css'

const Bread = ({ path }) => {
const router = useRouter();
let path_arr = path.split('/').filter(Boolean);

const breadCrumbItems = path_arr.map((path, index) => {
if (index == path_arr.length - 1) {
return {
title: path,
};
} else {
const href = '/tree?path=/' + path_arr.slice(0, index + 1).join('/');
return {
title: path,
href: href,
};
}

});

return (
<Breadcrumb className={styles.breadCrumb}
items={breadCrumbItems}
/>
);
};

export default Bread;
Loading
Loading