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
35 changes: 31 additions & 4 deletions gateway/src/api/ztm_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub fn routers() -> Router<MegaApiServiceState> {
.route("/ztm/repo_provide", post(repo_provide))
.route("/ztm/repo_fork", get(repo_folk))
.route("/ztm/peer_id", get(peer_id))
.route("/ztm/alias_to_path", get(alias_to_path))
}

async fn repo_provide(
Expand All @@ -38,10 +39,12 @@ 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())),
}
context
.services
.ztm_storage
.save_alias_mapping(model.clone())
.await
.map_err(|_| (StatusCode::BAD_REQUEST, String::from("Invalid Params")))?;
let res = match gemini::http::handler::repo_provide(
bootstrap_node,
state.inner.context.clone(),
Expand Down Expand Up @@ -108,3 +111,27 @@ async fn peer_id(
let (peer_id, _) = vault::init();
Ok(Json(CommonResult::success(Some(peer_id))))
}

async fn alias_to_path(
Query(query): Query<HashMap<String, String>>,
state: State<MegaApiServiceState>,
) -> Result<Json<CommonResult<String>>, (StatusCode, String)> {
let context = state.inner.context.clone();
let alias = match query.get("alias") {
Some(str) => str,
None => {
return Err((StatusCode::BAD_REQUEST, String::from("Alias not provide\n")));
}
};
let res = context
.services
.ztm_storage
.get_path_from_alias(alias)
.await
.map_err(|_| (StatusCode::BAD_REQUEST, String::from("Invalid Params")))?;
if let Some(res) = res {
Ok(Json(CommonResult::success(Some(res.repo_path))))
} else {
Err((StatusCode::BAD_REQUEST, String::from("Alias not found\n")))
}
}
6 changes: 5 additions & 1 deletion jupiter/src/storage/ztm_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@ impl ZTMStorage {
) -> Result<(), MegaError> {
ztm_path_mapping::Entity::insert(model.into_active_model())
.exec(self.get_connection())
.await?;
.await
.map_err(|err| {
tracing::error!("Error saving alias mapping: {}", err);
err
})?;
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion lunar/.env.local
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NEXT_PUBLIC_RELAY_API_URL=http://34.84.172.121
NEXT_PUBLIC_RELAY_API_URL=http://gitmono.org
NEXT_PUBLIC_API_URL=http://localhost:8000
11 changes: 7 additions & 4 deletions lunar/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ rust-version = "1.60"
tauri-build = { version = "1.5.3", features = [] }

[dependencies]
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.7.0", features = [ "shell-sidecar", "process-command-api"] }
serde_json = { workspace = true }
serde = { workspace = true, features = ["derive"] }
tauri = { version = "1.7.1", features = [
"shell-sidecar",
"process-command-api",
] }
tokio = { workspace = true }

[dev-dependencies]
[dev-dependencies]
tokio = { workspace = true, features = ["macros"] }

[features]
Expand Down
4 changes: 3 additions & 1 deletion lunar/src/app/api/fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ export async function requestPublishRepo(data) {
});

if (!response.ok) {
throw new Error('Failed to publish repo');
const errorResponse = await response.text();
const errorMessage = errorResponse || 'Failed to publish repo';
throw new Error(errorMessage);
}
return response.json();
}
39 changes: 28 additions & 11 deletions lunar/src/app/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,26 @@ 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, Skeleton } from "antd";
import { Button, Skeleton, message } from "antd";
import { usePeerId } from '@/app/api/fetcher'

interface MegaStartParams {
bootstrap_node: string,
}

export default function Settings() {

const [messageApi, contextHolder] = message.useMessage();

const success = () => {
messageApi.open({
type: 'success',
content: 'Save setting successful',
});
};

const [loadings, setLoadings] = useState<boolean[]>([]);
const [params, setParams] = useState<MegaStartParams>({
bootstrap_node: "http://34.84.172.121/relay",
bootstrap_node: "http://gitmono.org/relay",
});
const { peerId, isLoading, isError } = usePeerId();
if (isLoading) return <Skeleton />;
Expand All @@ -28,13 +36,14 @@ export default function Settings() {
newLoadings[index] = true;
return newLoadings;
});
setTimeout(() => {
setLoadings((prevLoadings) => {
const newLoadings = [...prevLoadings];
newLoadings[index] = false;
return newLoadings;
});
}, 6000);
}

const exitLoading = (index: number) => {
setLoadings((prevLoadings) => {
const newLoadings = [...prevLoadings];
newLoadings[index] = false;
return newLoadings;
});
}

const stopMega = async () => {
Expand All @@ -46,8 +55,15 @@ export default function Settings() {
const restartMega = async () => {
enterLoading(1);
invoke('restart_mega_service', { params: params })
.then((message) => console.log("result:", message))
.then((message) => {
console.log("result:", message);
success()
})
.catch((err) => console.error("err:", err));

setTimeout(() => {
exitLoading(1);
}, 1000);
};

const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
Expand All @@ -60,6 +76,7 @@ export default function Settings() {

return (
<form method="post" className="mx-auto max-w-4xl">
{contextHolder}
<Heading>Settings</Heading>
<Divider className="my-10 mt-6" />

Expand Down
40 changes: 29 additions & 11 deletions lunar/src/components/CodeTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useRouter, useSearchParams } from 'next/navigation'
import Markdown from 'react-markdown'
import { formatDistance, fromUnixTime } from 'date-fns'
import styles from './CodeTable.module.css'
import { Input, Modal, Space, Table, TableProps } from 'antd/lib'
import { Input, Modal, Space, Table, TableProps, message } from 'antd/lib'
import { useState } from 'react'
import {
FolderIcon,
Expand All @@ -23,6 +23,21 @@ export interface DataType {
}

const CodeTable = ({ directory, readmeContent, with_ztm }) => {
const [messageApi, contextHolder] = message.useMessage();

const msg_error = (content: String) => {
messageApi.open({
type: 'error',
content: content,
});
};
const msg_success = (content: String) => {
messageApi.open({
type: 'success',
content: content,
});
};

const router = useRouter();
const fileCodeContainerStyle = {
width: '100%',
Expand Down Expand Up @@ -79,7 +94,7 @@ const CodeTable = ({ directory, readmeContent, with_ztm }) => {
render: (_, record) => (
<Space size="middle">
<Button disabled={!with_ztm} onClick={() => showModal(record.name)}>Publish</Button>
<Button disabled={!with_ztm} outline>Revoke</Button>
{/* <Button disabled={!with_ztm} outline>Revoke</Button> */}
</Space>
),
},
Expand Down Expand Up @@ -134,17 +149,19 @@ const CodeTable = ({ directory, readmeContent, with_ztm }) => {
newPath = `${path}/${filename}`;
}
setConfirmLoading(true);
await requestPublishRepo({
"path": newPath,
"alias": filename,
})

try {
const result = await requestPublishRepo({
"path": newPath,
"alias": filename,
});
msg_success("Publish Success!");
console.log('Repo published successfully:', result);
} catch (error) {
msg_error("Publish failed:" + error);
}
setOpen(false);
setConfirmLoading(false);
// setTimeout(() => {
// console.log("publish path", newPath);
// setOpen(false);
// setConfirmLoading(false);
// }, 2000);
};

const handleCancel = () => {
Expand All @@ -153,6 +170,7 @@ const CodeTable = ({ directory, readmeContent, with_ztm }) => {

return (
<div style={fileCodeContainerStyle}>
{contextHolder}
<Table style={{ clear: "none" }} rowClassName={styles.dirShowTr} pagination={false} columns={columns} dataSource={sortedDir} />
<Modal
title="Given a alias for repo to public"
Expand Down
17 changes: 0 additions & 17 deletions lunar/src/components/catalyst/hello.tsx

This file was deleted.