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
24 changes: 0 additions & 24 deletions Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
8 changes: 6 additions & 2 deletions docker/mono-engine-dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
4 changes: 2 additions & 2 deletions docker/start-mono.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 1 addition & 12 deletions docker/start-moon.sh
Original file line number Diff line number Diff line change
@@ -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
exec npm run start
2 changes: 1 addition & 1 deletion gemini/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
9 changes: 7 additions & 2 deletions lunar/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
}
_ => {}
Expand All @@ -112,7 +116,6 @@ fn stop_mega_service(state: State<'_, Arc<Mutex<ServiceState>>>) -> 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");
}
Expand All @@ -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(())
}
Expand Down
2 changes: 1 addition & 1 deletion lunar/src/app/application-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export function ApplicationLayout({
<Alert
banner
message={
"Relay address is not configed, Some functions are not available"
"Relay server is not connected, Some functions are not available"
}
/>
}
Expand Down
2 changes: 1 addition & 1 deletion lunar/src/app/repo/page.tsx
Original file line number Diff line number Diff line change
@@ -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";


Expand Down
2 changes: 1 addition & 1 deletion lunar/src/app/settings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default function Settings() {
<section className="grid gap-x-8 gap-y-6 sm:grid-cols-2">
<div className="space-y-1">
<Subheading>ZTM Server IP Address</Subheading>
<Text>This will be restart Mega server.</Text>
<Text>Reboot Mega service after saving.</Text>
</div>
<div>
<Input disabled={loadings[1]} aria-label="Bootstrap Node" name="bootstrap_node"
Expand Down
4 changes: 0 additions & 4 deletions lunar/src/app/test/page.tsx

This file was deleted.

10 changes: 10 additions & 0 deletions moon/.env
Original file line number Diff line number Diff line change
@@ -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_ )
Empty file removed moon/.env.development
Empty file.
2 changes: 0 additions & 2 deletions moon/.env.local

This file was deleted.

1 change: 0 additions & 1 deletion moon/.env.production

This file was deleted.

10 changes: 10 additions & 0 deletions moon/next.config.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 1 addition & 2 deletions moon/src/app/api/auth/github/user/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
3 changes: 1 addition & 2 deletions moon/src/app/api/blob/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
11 changes: 11 additions & 0 deletions moon/src/app/api/env/route.ts
Original file line number Diff line number Diff line change
@@ -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' }
});
}
3 changes: 1 addition & 2 deletions moon/src/app/api/mr/[id]/detail/route.ts
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
3 changes: 1 addition & 2 deletions moon/src/app/api/mr/[id]/files/route.ts
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
3 changes: 1 addition & 2 deletions moon/src/app/api/mr/[id]/merge/route.ts
Original file line number Diff line number Diff line change
@@ -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',
})
Expand Down
3 changes: 1 addition & 2 deletions moon/src/app/api/mr/list/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`, {
Expand Down
2 changes: 1 addition & 1 deletion moon/src/app/api/tree/commit-info/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
5 changes: 2 additions & 3 deletions moon/src/app/api/tree/route.ts
Original file line number Diff line number Diff line change
@@ -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')

Expand Down
34 changes: 32 additions & 2 deletions moon/src/app/auth/github/callback/page.tsx
Original file line number Diff line number Diff line change
@@ -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<enviroment | null>(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 <div>Loading...</div>;
if (!data) return <div>Env Route Error</div>;

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)
Expand Down
2 changes: 0 additions & 2 deletions moon/src/app/login/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// 'use client'

export default function LoginLayout({ children }) {
return (

Expand Down
16 changes: 9 additions & 7 deletions moon/src/app/login/page.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<>
<div className="flex min-h-full flex-1 flex-col justify-center py-12 sm:px-6 lg:px-8">
<div className="sm:mx-auto sm:w-full sm:max-w-md">
<img
<Image
alt="Mega"
src="/images/megaLogo.png"
className="mx-auto h-10 w-auto"
width={10}
height={10}
/>

<h2 className="mt-6 text-center text-2xl font-bold leading-9 tracking-tight text-gray-900">
Expand Down Expand Up @@ -49,7 +51,7 @@ export default function Login() {
</a>

<a
href={`${apiUrl}/auth/github/authorize?redirect_uri=${call_back_url}`}
href={`${response.mega_host}/auth/github/authorize?redirect_uri=${response.callback_url}`}
className="flex w-full items-center justify-center gap-3 rounded-md bg-white px-3 py-2 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus-visible:ring-transparent"
>
<svg fill="currentColor" viewBox="0 0 20 20" aria-hidden="true" className="h-5 w-5 fill-[#24292F]">
Expand Down
Loading