bug fixes (#116)

* bug fixes

* fix ws url
This commit is contained in:
UUBulb
2025-02-05 18:46:42 +08:00
committed by GitHub
parent dfe7d57ea4
commit 9b63e4fbda
8 changed files with 30 additions and 29 deletions

View File

@@ -161,7 +161,8 @@ const FMComponent: React.FC<FMProps & JSX.IntrinsicElements["div"]> = ({ wsUrl,
}
useEffect(() => {
const ws = new WebSocket(wsUrl)
const url = new URL(wsUrl, window.location.origin)
const ws = new WebSocket(url)
wsRef.current = ws
ws.binaryType = "arraybuffer"
ws.onopen = () => {

View File

@@ -54,7 +54,17 @@ export const ServerConfigCardBatch: React.FC<ServerConfigCardBatchProps> = ({ si
setOpen(false)
}
return (
return sid.length < 1 ? (
<IconButton
{...props}
icon="cog"
onClick={() => {
toast(t("Error"), {
description: t("Results.NoRowsAreSelected"),
})
}}
/>
) : (
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<IconButton {...props} icon="cog" />
@@ -67,7 +77,7 @@ export const ServerConfigCardBatch: React.FC<ServerConfigCardBatchProps> = ({ si
<DialogDescription />
</DialogHeader>
<div className="flex flex-col gap-3 mt-4">
<Label>Option</Label>
<Label>{t("Option")}</Label>
<Input
type="text"
placeholder="option"
@@ -76,7 +86,7 @@ export const ServerConfigCardBatch: React.FC<ServerConfigCardBatchProps> = ({ si
setCurrentKey(e.target.value)
}}
/>
<Label>Value</Label>
<Label>{t("Value")}</Label>
<Textarea
className="resize-y"
value={currentVal}

View File

@@ -101,7 +101,7 @@ for (let i = 0; i < boolFields.length; i += 2) {
}
interface ServerConfigCardProps extends ButtonProps {
sid: number[]
sid: number
}
export const ServerConfigCard = ({ sid, ...props }: ServerConfigCardProps) => {
@@ -113,11 +113,7 @@ export const ServerConfigCard = ({ sid, ...props }: ServerConfigCardProps) => {
useEffect(() => {
const fetchData = async () => {
try {
if (sid.length > 1) {
setLoading(false)
return
}
const result = await getServerConfig(sid[0])
const result = await getServerConfig(sid)
setData(JSON.parse(result))
} catch (error) {
console.error(error)
@@ -168,7 +164,7 @@ export const ServerConfigCard = ({ sid, ...props }: ServerConfigCardProps) => {
values.hard_drive_partition_allowlist = values.hard_drive_partition_allowlist_raw
? JSON.parse(values.hard_drive_partition_allowlist_raw)
: undefined
resp = await setServerConfig({ config: JSON.stringify(values), servers: sid })
resp = await setServerConfig({ config: JSON.stringify(values), servers: [sid] })
} catch (e) {
console.error(e)
toast(t("Error"), {
@@ -187,17 +183,7 @@ export const ServerConfigCard = ({ sid, ...props }: ServerConfigCardProps) => {
form.reset()
}
return sid.length < 1 ? (
<IconButton
{...props}
icon="cog"
onClick={() => {
toast(t("Error"), {
description: t("Results.NoRowsAreSelected"),
})
}}
/>
) : (
return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<IconButton {...props} icon="cog" />

View File

@@ -53,7 +53,8 @@ const XtermComponent = forwardRef<HTMLDivElement, XtermProps & JSX.IntrinsicElem
cursorBlink: true,
fontSize: 16,
})
const ws = new WebSocket(wsUrl)
const url = new URL(wsUrl, window.location.origin)
const ws = new WebSocket(url)
wsRef.current = ws
ws.binaryType = "arraybuffer"
ws.onopen = () => {

View File

@@ -1,6 +1,7 @@
"use client"
import { useState } from "react"
import { useTranslation } from "react-i18next"
import { Label } from "../ui/label"
import { Textarea } from "../ui/textarea"
@@ -13,6 +14,7 @@ interface PusherProps {
export const Pusher: React.FC<PusherProps> = ({ property, setData }) => {
const [cData, setCData] = useState<Record<string, any>>({})
const { t } = useTranslation()
return (
<div className="flex flex-col gap-3">
@@ -43,7 +45,7 @@ export const Pusher: React.FC<PusherProps> = ({ property, setData }) => {
}}
/>
</div>
<Label>Preview</Label>
<Label>{t("Preview")}</Label>
<Textarea value={JSON.stringify(cData, null, 2)} readOnly />
</div>
)

View File

@@ -181,5 +181,8 @@
"EmptyText": "Text is empty",
"EmptyNote": "You didn't have any note.",
"OverrideDDNSDomains": "Override DDNS Domains (per configuration)",
"EditServerConfig": "Edit Server Config"
"EditServerConfig": "Edit Server Config",
"Option": "Option",
"Value": "Value",
"Preview": "Preview"
}

View File

@@ -145,7 +145,7 @@ export default function ServerPage() {
<>
<TerminalButton id={s.id} />
<ServerCard mutate={mutate} data={s} />
<ServerConfigCard sid={[s.id]} variant="outline" />
<ServerConfigCard sid={s.id} variant="outline" />
</>
</ActionButtonGroup>
)

View File

@@ -67,9 +67,7 @@ export default function SettingsPage() {
resolver: zodResolver(settingFormSchema),
defaultValues: config
? {
...config,
language: config?.config?.language,
site_name: config.config?.site_name || "",
...config.config,
user_template:
config.config?.user_template ||
Object.keys(config.frontend_templates?.filter((t) => !t.is_admin) || {})[0] ||