diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 40d393d9a..000000000 --- a/Dockerfile +++ /dev/null @@ -1,24 +0,0 @@ -# Use a Rust base image -FROM rust:latest as builder - -# Set the working directory -WORKDIR /usr/src/mega - -# Copy the Rust project files to the working directory -COPY . . - -# Build the Rust executable -RUN cargo build --release - -# Create a new image without the build dependencies -FROM debian:bookworm-slim - -# Set the working directory -WORKDIR /usr/src/mega - -# Copy the built executable from the builder stage -COPY --from=builder /usr/src/mega/target/release/mega /usr/local/bin/mega - -# Run the Rust executable command -# CMD ["./mega", "service", "https", "--host", "0.0.0.0"] -ENTRYPOINT ["mega"] \ No newline at end of file diff --git a/docker/README.md b/docker/README.md index cfb484cdf..1573ca816 100644 --- a/docker/README.md +++ b/docker/README.md @@ -40,5 +40,5 @@ docker network create mono-network # run postgres docker run --rm -it -d --name mono-pg --network mono-network -v /mnt/data/mono/pg-data:/var/lib/postgresql/data -p 5432:5432 mono-pg:0.1-pre-release docker run --rm -it -d --name mono-engine --network mono-network -v /mnt/data/mono/mono-data:/opt/mega -p 8000:8000 -p 22:9000 mono-engine:0.1-pre-release -docker run --rm -it -d --name mono-ui --network mono-network -e NEXT_PUBLIC_API_URL=http://mono-engine:8000 -p 3000:3000 mono-ui:0.1-pre-release +docker run --rm -it -d --name mono-ui --network mono-network -e MEGA_HOST=http://mono-engine:8000 -e MOON_HOST=http://localhost:3000 -p 3000:3000 mono-ui:0.1-pre-release ``` \ No newline at end of file diff --git a/docker/mono-engine-dockerfile b/docker/mono-engine-dockerfile index 996e18e82..1dc461b40 100644 --- a/docker/mono-engine-dockerfile +++ b/docker/mono-engine-dockerfile @@ -19,9 +19,13 @@ RUN if [ "$BUILD_TYPE" != "release" ] && [ "$BUILD_TYPE" != "debug" ]; then \ RUN apt-get update && apt-get install -y \ cmake \ clang \ + build-essential + +RUN apt-get install -y \ nodejs \ - npm \ - build-essential \ + npm + +RUN apt-get install -y \ curl \ wget \ file \ diff --git a/docker/start-mono.sh b/docker/start-mono.sh index 3e2c31e40..864d5561b 100755 --- a/docker/start-mono.sh +++ b/docker/start-mono.sh @@ -6,7 +6,7 @@ CONFIG_FILE="$MEGA_BASE_DIR/etc/config.toml" # check if config file exists if [ -f "$CONFIG_FILE" ]; then echo "Using config file: $CONFIG_FILE" - exec /usr/local/bin/mono -c "$CONFIG_FILE" service multi --host 0.0.0.0 --http-port 8000 --ssh-port 9000 + exec /usr/local/bin/mono -c "$CONFIG_FILE" service multi http ssh --host 0.0.0.0 --http-port 8000 --ssh-port 9000 else - exec /usr/local/bin/mono service multi --host 0.0.0.0 --ssh-port 22 + exec /usr/local/bin/mono service multi http ssh --host 0.0.0.0 --ssh-port 22 fi \ No newline at end of file diff --git a/docker/start-moon.sh b/docker/start-moon.sh index 135b6ccdb..feede2657 100755 --- a/docker/start-moon.sh +++ b/docker/start-moon.sh @@ -1,15 +1,4 @@ #!/bin/bash -NEXT_PUBLIC_CALLBACK_URL=http://0.0.0.0:3000/auth/github/callback - -# user must set the NEXT_PUBLIC_API_URL -if [ -z "$NEXT_PUBLIC_API_URL" ]; then - echo "NEXT_PUBLIC_API_URL is not set" - exit 1 -fi - -# write the environment variables to a file -echo "NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL" > .env.local -echo "NEXT_PUBLIC_CALLBACK_URL=$NEXT_PUBLIC_CALLBACK_URL" >> .env.local # TODO: run `npm run s start` didn't work, use `npm run dev` temporarily -exec npm run dev \ No newline at end of file +exec npm run start \ No newline at end of file diff --git a/gemini/src/util.rs b/gemini/src/util.rs index 673964b9e..cc2baf5ce 100644 --- a/gemini/src/util.rs +++ b/gemini/src/util.rs @@ -43,7 +43,7 @@ pub async fn handle_response( } } -pub fn repo_alias_to_identifier( alias: String) -> String { +pub fn repo_alias_to_identifier(alias: String) -> String { let (peer_id, _) = vault::init(); format!("p2p://{}/{alias}", peer_id.clone()) } diff --git a/lunar/src-tauri/src/main.rs b/lunar/src-tauri/src/main.rs index a9327b667..2e757b996 100644 --- a/lunar/src-tauri/src/main.rs +++ b/lunar/src-tauri/src/main.rs @@ -3,7 +3,7 @@ use std::path::PathBuf; use std::sync::{Arc, Mutex}; -use std::{env, fs}; +use std::{env, fs, thread, time}; use serde::Deserialize; use tauri::api::process::{Command, CommandChild, CommandEvent}; @@ -78,6 +78,7 @@ 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 { @@ -98,6 +99,9 @@ fn start_mega_service( } else if let Some(signal) = payload.signal { eprintln!("Sidecar terminated by signal: {}", signal); } + let mut service_state = cloned_state.lock().unwrap(); + service_state.child = None; + service_state.with_relay = false; break; } _ => {} @@ -112,7 +116,6 @@ 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"); } @@ -125,6 +128,8 @@ fn restart_mega_service( params: MegaStartParams, ) -> Result<(), String> { stop_mega_service(state.clone())?; + // wait for process exit + thread::sleep(time::Duration::from_millis(1000)); start_mega_service(state, params)?; Ok(()) } diff --git a/lunar/src/app/application-layout.tsx b/lunar/src/app/application-layout.tsx index 0e789080a..a4f495100 100644 --- a/lunar/src/app/application-layout.tsx +++ b/lunar/src/app/application-layout.tsx @@ -222,7 +222,7 @@ export function ApplicationLayout({ } diff --git a/lunar/src/app/repo/page.tsx b/lunar/src/app/repo/page.tsx index dc33ec96b..bec359376 100644 --- a/lunar/src/app/repo/page.tsx +++ b/lunar/src/app/repo/page.tsx @@ -1,7 +1,7 @@ 'use client' import RepoList from '@/components/RepoList' -import { useMegaStatus, useRepoList } from '@/app/api/fetcher'; +import { useRepoList } from '@/app/api/fetcher'; import { Skeleton } from "antd"; diff --git a/lunar/src/app/settings/page.tsx b/lunar/src/app/settings/page.tsx index 40d74a087..a1f709fd5 100644 --- a/lunar/src/app/settings/page.tsx +++ b/lunar/src/app/settings/page.tsx @@ -83,7 +83,7 @@ export default function Settings() {
ZTM Server IP Address - This will be restart Mega server. + Reboot Mega service after saving.
hello world
; -} diff --git a/moon/.env b/moon/.env new file mode 100644 index 000000000..b66d5d51a --- /dev/null +++ b/moon/.env @@ -0,0 +1,10 @@ +# Environment variables that start with NEXT_PUBLIC_ are exposed to clients. Make sure you don't expose sensitive information on the client side. +# Variables not prefixed with NEXT_PUBLIC_ are only available on the server side. + + +# add MEGA_HOST and MOON_HOST to your enviroment for development +# MEGA_HOST default to http://localhost:8000, MOON_HOST default to http://localhost:3000 +MEGA_HOST=$MEGA_HOST +CALLBACK_URL=$MOON_HOST/auth/github/callback + +SECRET_KEY=$YOUR_SECRET_KEY #(not prefixed with NEXT_PUBLIC_ ) \ No newline at end of file diff --git a/moon/.env.development b/moon/.env.development deleted file mode 100644 index e69de29bb..000000000 diff --git a/moon/.env.local b/moon/.env.local deleted file mode 100644 index 58a33cf5a..000000000 --- a/moon/.env.local +++ /dev/null @@ -1,2 +0,0 @@ -NEXT_PUBLIC_API_URL=http://localhost:8000 -NEXT_PUBLIC_CALLBACK_URL=http://localhost:3000/auth/github/callback \ No newline at end of file diff --git a/moon/.env.production b/moon/.env.production deleted file mode 100644 index 3339dfef8..000000000 --- a/moon/.env.production +++ /dev/null @@ -1 +0,0 @@ -NEXT_PUBLIC_API_URL=http://mega.api.com diff --git a/moon/next.config.js b/moon/next.config.js index 568c27213..d098ce912 100644 --- a/moon/next.config.js +++ b/moon/next.config.js @@ -1,6 +1,16 @@ /** @type {import('next').NextConfig} */ const nextConfig = { + images: { + remotePatterns: [ + { + protocol: 'https', + hostname: 'avatars.githubusercontent.com', + port: '', + pathname: '/u/**', + }, + ], + }, reactStrictMode: true, transpilePackages: [ // antd & deps diff --git a/moon/src/app/api/auth/github/user/route.ts b/moon/src/app/api/auth/github/user/route.ts index e5c0ca266..fa97ac34a 100644 --- a/moon/src/app/api/auth/github/user/route.ts +++ b/moon/src/app/api/auth/github/user/route.ts @@ -2,9 +2,8 @@ import { cookies } from "next/headers"; -const endpoint = process.env.NEXT_PUBLIC_API_URL; - export async function GET(request: Request) { + const endpoint = process.env.MEGA_HOST; const cookieStore = cookies(); const access_token = cookieStore.get('access_token'); diff --git a/moon/src/app/api/blob/route.ts b/moon/src/app/api/blob/route.ts index 089863b96..8622d4b98 100644 --- a/moon/src/app/api/blob/route.ts +++ b/moon/src/app/api/blob/route.ts @@ -3,9 +3,8 @@ import { type NextRequest } from 'next/server' export const dynamic = 'force-dynamic' // defaults to auto export const revalidate = 0 -const endpoint = process.env.NEXT_PUBLIC_API_URL; - export async function GET(request: NextRequest) { + const endpoint = process.env.MEGA_HOST; const searchParams = request.nextUrl.searchParams const path = searchParams.get('path') diff --git a/moon/src/app/api/env/route.ts b/moon/src/app/api/env/route.ts new file mode 100644 index 000000000..4ffdbc1d9 --- /dev/null +++ b/moon/src/app/api/env/route.ts @@ -0,0 +1,11 @@ +export const revalidate = 0 +export const dynamic = 'force-dynamic' // defaults to auto + +export async function GET() { + return new Response(JSON.stringify({ + mega_host: process.env.MEGA_HOST, + callback_url: process.env.CALLBACK_URL, + }), { + headers: { 'Content-Type': 'application/json' } + }); +} \ No newline at end of file diff --git a/moon/src/app/api/mr/[id]/detail/route.ts b/moon/src/app/api/mr/[id]/detail/route.ts index 0458babc6..f4e98114a 100644 --- a/moon/src/app/api/mr/[id]/detail/route.ts +++ b/moon/src/app/api/mr/[id]/detail/route.ts @@ -1,9 +1,8 @@ export const dynamic = 'force-dynamic' // defaults to auto export const revalidate = 0 -const endpoint = process.env.NEXT_PUBLIC_API_URL; - export async function GET(request: Request, { params }: { params: { id: string } }) { + const endpoint = process.env.MEGA_HOST; const res = await fetch(`${endpoint}/api/v1/mr/${params.id}/detail`, { }) const data = await res.json() diff --git a/moon/src/app/api/mr/[id]/files/route.ts b/moon/src/app/api/mr/[id]/files/route.ts index 5e97abcc3..07e07b9a0 100644 --- a/moon/src/app/api/mr/[id]/files/route.ts +++ b/moon/src/app/api/mr/[id]/files/route.ts @@ -1,8 +1,7 @@ export const dynamic = 'force-dynamic' // defaults to auto -const endpoint = process.env.NEXT_PUBLIC_API_URL; - export async function GET(request: Request, { params }: { params: { id: string } }) { + const endpoint = process.env.MEGA_HOST; const res = await fetch(`${endpoint}/api/v1/mr/${params.id}/files`, { }) const data = await res.json() diff --git a/moon/src/app/api/mr/[id]/merge/route.ts b/moon/src/app/api/mr/[id]/merge/route.ts index 2a73b20d7..134ef50b7 100644 --- a/moon/src/app/api/mr/[id]/merge/route.ts +++ b/moon/src/app/api/mr/[id]/merge/route.ts @@ -1,9 +1,8 @@ export const dynamic = 'force-dynamic' // defaults to auto -const endpoint = process.env.NEXT_PUBLIC_API_URL; - export async function POST(request: Request, { params }: { params: { id: string } }) { + const endpoint = process.env.MEGA_HOST; const res = await fetch(`${endpoint}/api/v1/mr/${params.id}/merge`, { method: 'POST', }) diff --git a/moon/src/app/api/mr/list/route.ts b/moon/src/app/api/mr/list/route.ts index b1b30c6bc..6e2a45a6e 100644 --- a/moon/src/app/api/mr/list/route.ts +++ b/moon/src/app/api/mr/list/route.ts @@ -3,9 +3,8 @@ export const revalidate = 0 import { type NextRequest } from 'next/server' -const endpoint = process.env.NEXT_PUBLIC_API_URL; - export async function GET(request: NextRequest) { + const endpoint = process.env.MEGA_HOST; const searchParams = request.nextUrl.searchParams const status = searchParams.get('status') const res = await fetch(`${endpoint}/api/v1/mr/list?status=${status}`, { diff --git a/moon/src/app/api/tree/commit-info/route.ts b/moon/src/app/api/tree/commit-info/route.ts index 25d9693ad..827b7440f 100644 --- a/moon/src/app/api/tree/commit-info/route.ts +++ b/moon/src/app/api/tree/commit-info/route.ts @@ -3,9 +3,9 @@ import { type NextRequest } from 'next/server' export const dynamic = 'force-dynamic' // defaults to auto export const revalidate = 0 -const endpoint = process.env.NEXT_PUBLIC_API_URL; export async function GET(request: NextRequest) { + const endpoint = process.env.MEGA_HOST; const searchParams = request.nextUrl.searchParams const path = searchParams.get('path') diff --git a/moon/src/app/api/tree/route.ts b/moon/src/app/api/tree/route.ts index d86b9bc05..863433f05 100644 --- a/moon/src/app/api/tree/route.ts +++ b/moon/src/app/api/tree/route.ts @@ -1,11 +1,10 @@ import { type NextRequest } from 'next/server' export const revalidate = 0 - export const dynamic = 'force-dynamic' // defaults to auto -const endpoint = process.env.NEXT_PUBLIC_API_URL; - export async function GET(request: NextRequest) { + const endpoint = process.env.MEGA_HOST; + const searchParams = request.nextUrl.searchParams const path = searchParams.get('path') diff --git a/moon/src/app/auth/github/callback/page.tsx b/moon/src/app/auth/github/callback/page.tsx index 049b9357d..6cb1bd253 100644 --- a/moon/src/app/auth/github/callback/page.tsx +++ b/moon/src/app/auth/github/callback/page.tsx @@ -1,15 +1,45 @@ 'use client' import { handleLogin } from '@/app/actions'; +import { useEffect, useState } from 'react'; + +interface enviroment { + mega_host: string; + callback_url: string; +} export default function AuthPage({ searchParams }) { - const apiUrl = process.env.NEXT_PUBLIC_API_URL; + const [data, setData] = useState(null); + const [loading, setLoading] = useState(true); + + useEffect(() => { + async function fetchData() { + try { + const res = await fetch(`http://localhost:3000/api/env`); + if (!res.ok) { + throw new Error('Failed to fetch data'); + } + const result = await res.json(); + setData(result); + } catch (error) { + console.error('Error fetching data:', error); + } finally { + setLoading(false); + } + } + + fetchData(); + }, []); + + if (loading) return
Loading...
; + if (!data) return
Env Route Error
; + const access_token = searchParams.access_token || ""; const code = searchParams.code || ""; const state = searchParams.state || ""; if (code && state) { - const targetUrl = `${apiUrl}/auth/github/callback?code=${code}&state=${state}`; + const targetUrl = `${data.mega_host}/auth/github/callback?code=${code}&state=${state}`; window.location.href = targetUrl; } else if (access_token) { handleLogin(access_token) diff --git a/moon/src/app/login/layout.tsx b/moon/src/app/login/layout.tsx index 426ab0e1d..47fc175e5 100644 --- a/moon/src/app/login/layout.tsx +++ b/moon/src/app/login/layout.tsx @@ -1,5 +1,3 @@ -// 'use client' - export default function LoginLayout({ children }) { return ( diff --git a/moon/src/app/login/page.tsx b/moon/src/app/login/page.tsx index a370e093b..24896af51 100644 --- a/moon/src/app/login/page.tsx +++ b/moon/src/app/login/page.tsx @@ -1,18 +1,20 @@ -// 'use client' +'use server' -export default function Login() { - - const apiUrl = process.env.NEXT_PUBLIC_API_URL; - const call_back_url = process.env.NEXT_PUBLIC_CALLBACK_URL; +import Image from "next/image"; +export default async function Login() { + const res = await fetch(`http://localhost:3000/api/env`); + const response = await res.json(); return ( <>
- Mega

@@ -49,7 +51,7 @@ export default function Login() {
diff --git a/moon/src/components/RepoTree.tsx b/moon/src/components/RepoTree.tsx index d95d5d701..0a0f56a11 100644 --- a/moon/src/components/RepoTree.tsx +++ b/moon/src/components/RepoTree.tsx @@ -1,6 +1,6 @@ import 'github-markdown-css/github-markdown-light.css' import { DownOutlined } from '@ant-design/icons/lib' -import { useState, useEffect } from 'react' +import { useState, useEffect, useCallback } from 'react' import { useRouter } from 'next/navigation' import { Tree } from 'antd/lib' import styles from './RepoTree.module.css' @@ -11,22 +11,8 @@ const RepoTree = ({ directory }) => { const [updateTree, setUpdateTree] = useState(false); const [expandedKeys, setExpandedKeys] = useState([]); - useEffect(() => { - setTreeData(convertToTreeData(directory)); - }, [directory]); - - - useEffect(() => { - if (updateTree) { - setUpdateTree(false); - } - }, [updateTree]); - - - - // convert the dir to tree data - const convertToTreeData = (responseData) => { - return sortProjectsByType(responseData).map(item => { + const convertToTreeData = useCallback((directory) => { + return sortProjectsByType(directory).map(item => { const treeItem = { title: item.name, key: item.id, @@ -37,7 +23,18 @@ const RepoTree = ({ directory }) => { }; return treeItem; }); - }; + }, []); + + useEffect(() => { + setTreeData(convertToTreeData(directory)); + }, [directory, convertToTreeData]); + + + useEffect(() => { + if (updateTree) { + setUpdateTree(false); + } + }, [updateTree]); // sortProjectsByType function to sort projects by file type const sortProjectsByType = (projects) => { diff --git a/moon/src/components/catalyst/avatar.tsx b/moon/src/components/catalyst/avatar.tsx index ed21e313e..3fb6ba642 100644 --- a/moon/src/components/catalyst/avatar.tsx +++ b/moon/src/components/catalyst/avatar.tsx @@ -3,6 +3,7 @@ import clsx from 'clsx' import React, { forwardRef } from 'react' import { TouchTarget } from './button' import { Link } from './link' +import Image from 'next/image' type AvatarProps = { src?: string | null @@ -45,7 +46,7 @@ export function Avatar({ )} - {src && {alt}} + {src && {alt}} ) }