From 6f8a2b5928ae40aca2aa38abefe9295365b8e13f Mon Sep 17 00:00:00 2001 From: ppc Date: Wed, 7 Aug 2024 17:53:07 +0100 Subject: [PATCH] add https/port warnings --- aimenet-web/app/page.tsx | 148 +++++++++++++++++++++++++++++---------- 1 file changed, 111 insertions(+), 37 deletions(-) diff --git a/aimenet-web/app/page.tsx b/aimenet-web/app/page.tsx index 2a88a72..23794ef 100644 --- a/aimenet-web/app/page.tsx +++ b/aimenet-web/app/page.tsx @@ -1,20 +1,31 @@ "use client"; import {z} from "zod"; -import React from "react"; +import Link from "next/link"; +import React, {useState} from "react"; import TimeAgo from "react-timeago"; import {useForm} from "react-hook-form"; import {useRouter} from "next/navigation"; -import {ChevronRight, Earth, History, Loader, Plus, Trash} from "lucide-react"; +import {AppRouterInstance} from "next/dist/shared/lib/app-router-context.shared-runtime"; +import { + ChevronRight, + Earth, + History, + Loader, + Network, + Plus, + ShieldAlert, + SquareArrowOutUpRight, + Trash +} from "lucide-react"; import {useLiveQuery} from "dexie-react-hooks"; import {AimeServer, db} from "@/lib/database"; import {zodResolver} from "@hookform/resolvers/zod"; - import {Card} from "@/components/ui/card"; import {Input} from "@/components/ui/input"; import {Button} from "@/components/ui/button"; +import {Footer} from "@/components/ui/footer"; import {Separator} from "@/components/ui/separator"; -import {Form, FormControl, FormField, FormItem, FormMessage} from "@/components/ui/form"; import { ContextMenu, ContextMenuContent, @@ -22,11 +33,11 @@ import { ContextMenuSeparator, ContextMenuTrigger } from "@/components/ui/context-menu"; -import {AppRouterInstance} from "next/dist/shared/lib/app-router-context.shared-runtime"; -import {Footer} from "@/components/ui/footer"; +import {Alert, AlertDescription, AlertTitle} from "@/components/ui/alert"; +import {Form, FormControl, FormField, FormItem, FormMessage} from "@/components/ui/form"; const serverAdditionSchema = z.object({ - address: z.string().min(14).startsWith("http") + address: z.string().startsWith("http") }); function redirectToServerPage(router: AppRouterInstance, server: AimeServer) { @@ -47,10 +58,13 @@ function ServerList(props: { servers: AimeServer[] | undefined }) { if (!props.servers.length) { return ( -
- - No servers found. Add one below! -
+ <> +
+ + No servers found. Add one below! +
+ + ); } @@ -63,10 +77,12 @@ function ServerList(props: { servers: AimeServer[] | undefined }) {

{s.name}

-
- - -
+ {s.lastConnected > 0 && ( +
+ + +
+ )}
{s.address} @@ -84,7 +100,7 @@ function ServerList(props: { servers: AimeServer[] | undefined }) { Select Server - + db.servers.delete(s.id)}> Remove Server @@ -100,6 +116,10 @@ function ServerAddForm() { resolver: zodResolver(serverAdditionSchema) }); + const [showHttpsWarning, setHttpsWarning] = useState(false); + const [showPortWarning, setPortWarning] = useState(false); + const [blockSubmit, setBlockSubmit] = useState(true); + async function onSubmit(values: z.infer) { const existingServer = await db.servers .where("address") @@ -111,8 +131,13 @@ function ServerAddForm() { if (!existingServer) { const newId = await db.servers.add({ name: "Server", - address: values.address, - lastConnected: Date.now() + lastConnected: 0, + address: values.address + }); + + // set server name using id + await db.servers.update(newId, { + name: `Server #${newId}` }); router.push(`/servers/${newId}`); @@ -121,26 +146,75 @@ function ServerAddForm() { } } + function handleAddressChange(event: React.ChangeEvent, callback: (value: React.ChangeEvent) => void) { + try { + const address = new URL(event.target.value); + + setBlockSubmit(false); + setPortWarning(!address.port); + setHttpsWarning(address.protocol !== "http:"); + } catch { + setBlockSubmit(true); + setPortWarning(false); + setHttpsWarning(false); + } + + callback(event); + } + return ( -
- - ( - - - - - - - )} - /> - - - + <> + {(showHttpsWarning || showPortWarning) && (
)} + {showHttpsWarning && ( + + + HTTPS Warning + + AimeNet doesn't support HTTPS out-the-box. + If you're using HTTPS, ensure a reverse-proxy or + HTTP.SYS + has been configured and a valid, trusted SSL certificate has been configured. + + + )} + + {(showPortWarning && !showHttpsWarning) && ( + + + Default Port Detected + + Ensure you've set the correct port in the address field. By default, AimeNet uses + port 6070. + + + )} + +
+ + ( + + + handleAddressChange(e, field.onChange)}/> + + + + )} + /> + + + + ); }