Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
lerte committed Apr 15, 2024
1 parent 5f72b6c commit c91b7eb
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 47 deletions.
14 changes: 1 addition & 13 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"runtime/debug"
"zroker/zrok"

"github.com/gofiber/fiber/v2/log"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/sdk/golang/sdk"
"github.com/wailsapp/wails/v2/pkg/runtime"
Expand Down Expand Up @@ -98,18 +97,7 @@ func (a *App) Overview() string {
}

func (a *App) Sharing(shareRequest sdk.ShareRequest) *sdk.Share {
root,_ := environment.LoadRoot()
share,err := sdk.CreateShare(root, &sdk.ShareRequest{
BackendMode: shareRequest.BackendMode,
ShareMode: shareRequest.ShareMode,
Frontends: []string{"public"}, // 不是很懂这个参数
Target: shareRequest.Target,
})
if(err != nil){
log.Error("error", err)
}
log.Info("share", share)
return share
return zrok.Sharing(shareRequest)
}

// Open link in browser
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
de2fdbf1f33b1f587fd3dd6db0957c2e
b73133a2876821f79d7e3e9e244623fe
4 changes: 2 additions & 2 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { EnableProvider } from "./contexts/Enable";
import { useAutoDark } from "./hooks/useAutoDark";

const App = () => {
const [theme] = useAutoDark();
const [theme, setTheme] = useAutoDark();
const [dark, setDark] = useState(false);

useEffect(() => {
Expand All @@ -23,7 +23,7 @@ const App = () => {
accentColor="crimson"
>
<EnableProvider>
<Zroker />
<Zroker setTheme={setTheme} />
</EnableProvider>
<Toaster
position="bottom-right"
Expand Down
22 changes: 16 additions & 6 deletions frontend/src/Zroker.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
import { Flex } from "@radix-ui/themes";
import { isDark } from "./utils";
import Login from "./components/Login";
import Overview from "./components/Overview";
import { useEnable } from "./contexts/Enable";
import { Sun, Moon } from "lucide-react";
import { Theme } from "./hooks/useAutoDark";
import { Box, Button, Flex } from "@radix-ui/themes";

const Zroker = () => {
const Zroker = ({ setTheme }: { setTheme: (theme: Theme) => void }) => {
const { enable } = useEnable();

return (
<Flex
gap="4"
className="h-dvh p-4"
>
<Flex className="h-dvh p-4">
{enable ? <Overview /> : <Login />}
<Box className="absolute right-12 top-12 !flex gap-4">
<Button
size="4"
radius="full"
variant="ghost"
onClick={() => setTheme(isDark() ? "light" : "dark")}
>
{isDark() ? <Moon /> : <Sun />}
</Button>
</Box>
</Flex>
);
};
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Enable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const EnablePage = () => {
} else {
const ok = await Enable(token);
if (ok) {
toast.success("Enable success");
toast.success("Enabled successfully");
setEnable(true);
} else {
toast.error("Enable failed");
Expand Down
52 changes: 39 additions & 13 deletions frontend/src/components/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import dayjs from "dayjs";
import Sharing from "./Sharing";
import toast from "react-hot-toast";
import { useEffect, useState } from "react";
import { XCircle, CopyIcon, Plus, Delete, RefreshCw } from "lucide-react";
import { Share, Environment } from "../../types/zrok";
import { XCircle, CopyIcon, Plus, Delete, RefreshCw } from "lucide-react";
import { Overview, OpenExternal, DeleteShare } from "../../wailsjs/go/main/App";
import {
Box,
Expand All @@ -12,11 +12,12 @@ import {
Link,
Table,
Badge,
Card,
Button,
Dialog,
ScrollArea,
IconButton,
Separator,
Card,
} from "@radix-ui/themes";

type Environments = {
Expand All @@ -35,6 +36,7 @@ const Page = () => {
const getOverview = async () => {
setLoading(true);
const overview = await Overview();
console.log(overview);

const { environments }: { environments: Environments[] } =
JSON.parse(overview);
Expand All @@ -48,11 +50,15 @@ const Page = () => {

useEffect(() => {
if (!loading) {
setShares(environments[0]?.shares?.reverse() ?? []);
setShares(environments[1]?.shares?.reverse() ?? []);
}
}, [loading]);

const handleClickFrontendEndpoint = (url: string) => {
const openExternal = (
event: React.MouseEvent<HTMLAnchorElement, MouseEvent>,
url: string
) => {
event.stopPropagation();
if (url == "private") {
return;
}
Expand All @@ -72,10 +78,10 @@ const Page = () => {
});

if (ok) {
toast.success("删除成功");
toast.success("Delete successful");
setShares([...shares.filter((item) => item.token != share.token)]);
} else {
toast.error("删除失败");
toast.error("Delete failed");
}
setIsLoading(false);
setCurrent({} as Share);
Expand Down Expand Up @@ -151,11 +157,11 @@ const Page = () => {
<Table.Header>
<Table.Row>
<Table.ColumnHeaderCell>backendMode</Table.ColumnHeaderCell>
<Table.ColumnHeaderCell>shareMode</Table.ColumnHeaderCell>
<Table.ColumnHeaderCell>frontendEndpoint</Table.ColumnHeaderCell>
<Table.ColumnHeaderCell>
backendProxyEndpoint
</Table.ColumnHeaderCell>
<Table.ColumnHeaderCell>frontendEndpoint</Table.ColumnHeaderCell>
<Table.ColumnHeaderCell>shareMode</Table.ColumnHeaderCell>
<Table.ColumnHeaderCell>createdAt</Table.ColumnHeaderCell>
<Table.ColumnHeaderCell>actions</Table.ColumnHeaderCell>
</Table.Row>
Expand Down Expand Up @@ -190,7 +196,9 @@ const Page = () => {
<Table.Cell>
<Link
href="#"
onClick={() => OpenExternal(share.backendProxyEndpoint)}
onClick={(event) =>
openExternal(event, share.backendProxyEndpoint)
}
>
{share.backendProxyEndpoint}
</Link>
Expand All @@ -201,8 +209,8 @@ const Page = () => {
) : (
<Link
href="#"
onClick={() =>
handleClickFrontendEndpoint(share.frontendEndpoint)
onClick={(event) =>
openExternal(event, share.frontendEndpoint)
}
>
{share.frontendEndpoint}
Expand Down Expand Up @@ -257,7 +265,9 @@ const Page = () => {
>
{current.token}
</Text>
<CopyIcon className="cursor-pointer" />
<IconButton variant="ghost">
<CopyIcon className="cursor-pointer" />
</IconButton>
</Flex>
<Flex gap="5">
<Text
Expand All @@ -272,7 +282,23 @@ const Page = () => {
>
{current.zId}
</Text>
<CopyIcon className="cursor-pointer" />
<IconButton variant="ghost">
<CopyIcon className="cursor-pointer" />
</IconButton>
</Flex>
<Flex gap="5">
<Text
size="5"
className="basis-1/5"
>
createdAt
</Text>
<Text
size="5"
className="basis-3/5"
>
{dayjs(current.createdAt).format("YYYY/M/DD HH:mm:ss")}
</Text>
</Flex>
<Flex gap="5">
<Text
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/hooks/useAutoDark.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState, useEffect } from "react";

type Theme = "inherit" | "light" | "dark";
export type Theme = "inherit" | "light" | "dark";

export const useAutoDark = () => {
const [theme, setTheme] = useState<Theme>("dark");
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/muhlemmer/gu v0.3.1 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/onsi/gomega v1.27.6 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/openziti/channel/v2 v2.0.119 // indirect
github.com/openziti/edge-api v0.26.10 // indirect
Expand Down Expand Up @@ -73,7 +74,7 @@ require (
go.opentelemetry.io/otel/metric v1.21.0 // indirect
go.opentelemetry.io/otel/trace v1.21.0 // indirect
golang.org/x/oauth2 v0.16.0 // indirect
golang.org/x/sync v0.5.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/term v0.19.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.32.0 // indirect
Expand All @@ -85,11 +86,10 @@ require (
require (
github.com/bep/debounce v1.2.1 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gofiber/fiber/v2 v2.52.4
github.com/google/uuid v1.6.0 // indirect
github.com/jchv/go-winloader v0.0.0-20210711035445-715c2860da7e // indirect
github.com/labstack/echo/v4 v4.10.2 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/labstack/gommon v0.4.0
github.com/leaanthony/go-ansi-parser v1.6.0 // indirect
github.com/leaanthony/gosod v1.0.3 // indirect
github.com/leaanthony/slicer v1.6.0 // indirect
Expand Down
11 changes: 4 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ github.com/go-resty/resty/v2 v2.11.0/go.mod h1:iiP/OpA0CkcL3IGt1O0+/SIItFUbkkyw5
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gofiber/fiber/v2 v2.52.4 h1:P+T+4iK7VaqUsq2PALYEfBBo6bJZ4q3FP8cZ84EggTM=
github.com/gofiber/fiber/v2 v2.52.4/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/golang-jwt/jwt/v5 v5.2.0 h1:d/ix8ftRUorsN+5eMIlF4T6J8CAt9rch3My2winC1Jw=
github.com/golang-jwt/jwt/v5 v5.2.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
Expand Down Expand Up @@ -326,8 +324,8 @@ github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vv
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48=
github.com/onsi/gomega v1.13.0 h1:7lLHu94wT9Ij0o6EWWclhu0aOh32VxhkwEJvzuWPeak=
github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY=
github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE=
github.com/onsi/gomega v1.27.6/go.mod h1:PIQNjfQwkP3aQAH7lf7j87O/5FiNr+ZR8+ipb+qQlhg=
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/openziti/channel/v2 v2.0.119 h1:stfSrnDqoTi78LMvQA3+NSivHjQnRrYKrgij5NaOENI=
Expand Down Expand Up @@ -601,8 +599,8 @@ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -881,7 +879,6 @@ gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
22 changes: 22 additions & 0 deletions zrok/share.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package zrok

import (
"github.com/labstack/gommon/log"
"github.com/openziti/zrok/environment"
"github.com/openziti/zrok/sdk/golang/sdk"
)

func Sharing(shareRequest sdk.ShareRequest) *sdk.Share {
root, _ := environment.LoadRoot()
share, err := sdk.CreateShare(root, &sdk.ShareRequest{
BackendMode: shareRequest.BackendMode,
ShareMode: shareRequest.ShareMode,
Frontends: []string{"public"}, // 不是很懂这个参数
Target: shareRequest.Target,
})
if err != nil {
log.Error("error", err)
}
log.Info("share", share)
return share
}

0 comments on commit c91b7eb

Please sign in to comment.