From 2da8565e475da988052d9016caa3ee79b83a9544 Mon Sep 17 00:00:00 2001 From: Bot Date: Fri, 1 May 2026 13:55:01 +0800 Subject: [PATCH] fix: stabilize admin frontend and resolve TS build errors --- src/components/notifier.tsx | 1 - src/hooks/useNotfication.tsx | 2 +- src/hooks/useServer.tsx | 2 +- src/routes/alert-rule.tsx | 4 ++-- src/routes/cron.tsx | 6 +++--- src/routes/ddns.tsx | 4 ++-- src/routes/nat.tsx | 4 ++-- src/routes/notification-group.tsx | 4 ++-- src/routes/notification.tsx | 6 +++--- src/routes/online-user.tsx | 12 ++++++------ src/routes/root.tsx | 3 +-- src/routes/server-group.tsx | 4 ++-- src/routes/service.tsx | 4 ++-- src/routes/settings.tsx | 4 ++-- src/routes/user.tsx | 4 ++-- src/routes/waf.tsx | 6 +++--- src/types/api.ts | 9 +++++++++ 17 files changed, 43 insertions(+), 36 deletions(-) diff --git a/src/components/notifier.tsx b/src/components/notifier.tsx index d3ad6d3..117c10b 100644 --- a/src/components/notifier.tsx +++ b/src/components/notifier.tsx @@ -30,7 +30,6 @@ import { SelectValue, } from "@/components/ui/select" import { IconButton } from "@/components/xui/icon-button" -import { asOptionalField } from "@/lib/utils" import { ModelNotification } from "@/types" import { nrequestMethods, nrequestTypes } from "@/types" import { zodResolver } from "@hookform/resolvers/zod" diff --git a/src/hooks/useNotfication.tsx b/src/hooks/useNotfication.tsx index 855a322..e3bd8b1 100644 --- a/src/hooks/useNotfication.tsx +++ b/src/hooks/useNotfication.tsx @@ -45,7 +45,7 @@ export const NotificationProvider: React.FC = ({ (async () => { try { const n = (await getNotification()) || [] - const nData = n.map(({ id, name }) => ({ id, name })) + const nData = n.map(({ id, name }) => ({ id: id!, name })) setNotifier(nData) } catch (error: any) { toast("NotificationProvider Error", { diff --git a/src/hooks/useServer.tsx b/src/hooks/useServer.tsx index 2942526..45fd651 100644 --- a/src/hooks/useServer.tsx +++ b/src/hooks/useServer.tsx @@ -45,7 +45,7 @@ export const ServerProvider: React.FC = ({ (async () => { try { const s = (await getServers()) || [] - const serverData = s.map(({ id, name }) => ({ id, name })) + const serverData = s.map(({ id, name }) => ({ id: id!, name })) setServer(serverData) } catch (error: any) { toast("ServerProvider Error", { diff --git a/src/routes/alert-rule.tsx b/src/routes/alert-rule.tsx index 11ac8f4..c972a16 100644 --- a/src/routes/alert-rule.tsx +++ b/src/routes/alert-rule.tsx @@ -116,7 +116,7 @@ export default function AlertRulePage() { className="flex gap-2" delete={{ fn: deleteAlertRules, - id: s.id, + id: s.id!, mutate: mutate, }} > @@ -147,7 +147,7 @@ export default function AlertRulePage() { className="flex ml-auto self-end sm:self-auto gap-2 flex-wrap shrink-0" delete={{ fn: deleteAlertRules, - id: selectedRows.map((r) => r.original.id), + id: selectedRows.map((r) => r.original.id!), mutate: mutate, }} > diff --git a/src/routes/cron.tsx b/src/routes/cron.tsx index e37a4e7..d35f63e 100644 --- a/src/routes/cron.tsx +++ b/src/routes/cron.tsx @@ -164,7 +164,7 @@ export default function CronPage() { return ( <> { try { - await runCron(s.id) + await runCron(s.id!) } catch (e) { console.error(e) toast(t("Error"), { @@ -215,7 +215,7 @@ export default function CronPage() { className="flex gap-2 flex-wrap shrink-0" delete={{ fn: deleteCron, - id: selectedRows.map((r) => r.original.id), + id: selectedRows.map((r) => r.original.id!), mutate: mutate, }} > diff --git a/src/routes/ddns.tsx b/src/routes/ddns.tsx index 313f35c..a0223db 100644 --- a/src/routes/ddns.tsx +++ b/src/routes/ddns.tsx @@ -121,7 +121,7 @@ export default function DDNSPage() { className="flex gap-2" delete={{ fn: deleteDDNSProfiles, - id: s.id, + id: s.id!, mutate: mutate, }} > @@ -152,7 +152,7 @@ export default function DDNSPage() { className="flex ml-auto self-end sm:self-auto gap-2 flex-wrap shrink-0" delete={{ fn: deleteDDNSProfiles, - id: selectedRows.map((r) => r.original.id), + id: selectedRows.map((r) => r.original.id!), mutate: mutate, }} > diff --git a/src/routes/nat.tsx b/src/routes/nat.tsx index 9d35dfa..b71eaeb 100644 --- a/src/routes/nat.tsx +++ b/src/routes/nat.tsx @@ -106,7 +106,7 @@ export default function NATPage() { return ( @@ -135,7 +135,7 @@ export default function NATPage() { className="flex ml-auto self-end sm:self-auto gap-2 flex-wrap shrink-0" delete={{ fn: deleteNAT, - id: selectedRows.map((r) => r.original.id), + id: selectedRows.map((r) => r.original.id!), mutate: mutate, }} > diff --git a/src/routes/notification-group.tsx b/src/routes/notification-group.tsx index 523e0ac..3d7082a 100644 --- a/src/routes/notification-group.tsx +++ b/src/routes/notification-group.tsx @@ -97,7 +97,7 @@ export default function NotificationGroupPage() { className="flex gap-2" delete={{ fn: deleteNotificationGroups, - id: s.group.id, + id: s.group.id!, mutate: mutate, }} > @@ -128,7 +128,7 @@ export default function NotificationGroupPage() { className="flex ml-auto self-end sm:self-auto gap-2 flex-wrap shrink-0" delete={{ fn: deleteNotificationGroups, - id: selectedRows.map((r) => r.original.group.id), + id: selectedRows.map((r) => r.original.group.id!), mutate: mutate, }} > diff --git a/src/routes/notification.tsx b/src/routes/notification.tsx index d4bf20a..5965c25 100644 --- a/src/routes/notification.tsx +++ b/src/routes/notification.tsx @@ -83,7 +83,7 @@ export default function NotificationPage() { accessorFn: (row) => { return ( notifierGroup - ?.filter((ng) => ng.notifications?.includes(row.id)) + ?.filter((ng) => ng.notifications?.includes(row.id!)) .map((ng) => ng.group.id) || [] ) }, @@ -112,7 +112,7 @@ export default function NotificationPage() { className="flex gap-2" delete={{ fn: deleteNotification, - id: s.id, + id: s.id!, mutate: mutate, }} > @@ -143,7 +143,7 @@ export default function NotificationPage() { className="flex ml-auto self-end sm:self-auto gap-2 flex-wrap shrink-0" delete={{ fn: deleteNotification, - id: selectedRows.map((r) => r.original.id), + id: selectedRows.map((r) => r.original.id!), mutate: mutate, }} > diff --git a/src/routes/online-user.tsx b/src/routes/online-user.tsx index 850f3ae..bbb94a3 100644 --- a/src/routes/online-user.tsx +++ b/src/routes/online-user.tsx @@ -22,7 +22,7 @@ import { TableRow, } from "@/components/ui/table" import { useAuth } from "@/hooks/useAuth" -import { ModelOnlineUser, ModelOnlineUserApi } from "@/types" +import { GithubComNezhahqNezhaModelPaginatedResponseArrayModelOnlineUserModelOnlineUser, ModelOnlineUser } from "@/types" import { ColumnDef, flexRender, getCoreRowModel, useReactTable } from "@tanstack/react-table" import { useEffect, useMemo } from "react" import { useTranslation } from "react-i18next" @@ -40,7 +40,7 @@ export default function OnlineUserPage() { // 计算 offset const offset = (page - 1) * pageSize - const { data, mutate, error, isLoading } = useSWR( + const { data, mutate, error, isLoading } = useSWR( `/api/v1/online-user?offset=${offset}&limit=${pageSize}`, swrFetcher, ) @@ -94,7 +94,7 @@ export default function OnlineUserPage() { accessorFn: (row) => row.connected_at, cell: ({ row }) => { const s = row.original - const date = new Date(s.connected_at) + const date = new Date(s.connected_at!) return {date.toISOString()} }, }, @@ -125,7 +125,7 @@ export default function OnlineUserPage() { } const dataCache = useMemo(() => { - return data?.value ?? [] + return data?.data?.value ?? [] }, [data]) const table = useReactTable({ @@ -137,9 +137,9 @@ export default function OnlineUserPage() { const selectedRows = table.getSelectedRowModel().rows const renderPagination = () => { - if (!data?.pagination) return null + if (!data?.data?.pagination) return null - const { total } = data.pagination + const { total = 0 } = data.data.pagination const totalPages = Math.ceil(total / pageSize) const handlePageChange = (newPage: number) => { diff --git a/src/routes/root.tsx b/src/routes/root.tsx index 967ab6d..2b2d930 100644 --- a/src/routes/root.tsx +++ b/src/routes/root.tsx @@ -4,8 +4,7 @@ import { Toaster } from "@/components/ui/sonner" import useSetting from "@/hooks/useSetting" import i18n from "@/lib/i18n" import { InjectContext } from "@/lib/inject" -import { DateTime } from "luxon" -import { useEffect, useState } from "react" +import { useEffect } from "react" import { useTranslation } from "react-i18next" import { Outlet } from "react-router-dom" diff --git a/src/routes/server-group.tsx b/src/routes/server-group.tsx index 98fec61..fe89efb 100644 --- a/src/routes/server-group.tsx +++ b/src/routes/server-group.tsx @@ -97,7 +97,7 @@ export default function ServerGroupPage() { className="flex gap-2" delete={{ fn: deleteServerGroups, - id: s.group.id, + id: s.group.id!, mutate: mutate, }} > @@ -128,7 +128,7 @@ export default function ServerGroupPage() { className="flex ml-auto self-end sm:self-auto gap-2 flex-wrap shrink-0" delete={{ fn: deleteServerGroups, - id: selectedRows.map((r) => r.original.group.id), + id: selectedRows.map((r) => r.original.group.id!), mutate: mutate, }} > diff --git a/src/routes/service.tsx b/src/routes/service.tsx index 27d711a..16f5fe3 100644 --- a/src/routes/service.tsx +++ b/src/routes/service.tsx @@ -152,7 +152,7 @@ export default function ServicePage() { return ( @@ -181,7 +181,7 @@ export default function ServicePage() { className="flex gap-2 flex-wrap shrink-0" delete={{ fn: deleteService, - id: selectedRows.map((r) => r.original.id), + id: selectedRows.map((r) => r.original.id!), mutate: mutate, }} > diff --git a/src/routes/settings.tsx b/src/routes/settings.tsx index 243dc7e..d1ed412 100644 --- a/src/routes/settings.tsx +++ b/src/routes/settings.tsx @@ -260,7 +260,7 @@ export default function SettingsPage() { Telegram Bot Token - + @@ -273,7 +273,7 @@ export default function SettingsPage() { Telegram Admin Chat ID - + diff --git a/src/routes/user.tsx b/src/routes/user.tsx index e05c274..6f4d62c 100644 --- a/src/routes/user.tsx +++ b/src/routes/user.tsx @@ -90,7 +90,7 @@ export default function UserPage() { className="flex gap-2" delete={{ fn: deleteUser, - id: s.id, + id: s.id!, mutate: mutate, }} > @@ -121,7 +121,7 @@ export default function UserPage() { className="flex-2 flex gap-2 ml-auto" delete={{ fn: deleteUser, - id: selectedRows.map((r) => r.original.id), + id: selectedRows.map((r) => r.original.id!), mutate: mutate, }} > diff --git a/src/routes/waf.tsx b/src/routes/waf.tsx index c547ded..7bd75d0 100644 --- a/src/routes/waf.tsx +++ b/src/routes/waf.tsx @@ -98,13 +98,13 @@ export default function WAFPage() { header: t("LastBlockReason"), accessorKey: "lastBlockReason", accessorFn: (row) => row.block_reason, - cell: ({ row }) => {wafBlockReasons[row.original.block_reason] || ""}, + cell: ({ row }) => {wafBlockReasons[row.original.block_reason!] || ""}, }, { header: t("BlockIdentifier"), accessorKey: "BlockIdentifier", accessorFn: (row) => { - return wafBlockIdentifiers[row.block_identifier] || row.block_identifier + return wafBlockIdentifiers[row.block_identifier!] || row.block_identifier }, }, { @@ -158,7 +158,7 @@ export default function WAFPage() { const renderPagination = () => { if (!data?.pagination) return null - const { total } = data.pagination + const { total = 0 } = data.pagination const totalPages = Math.ceil(total / pageSize) const handlePageChange = (newPage: number) => { diff --git a/src/types/api.ts b/src/types/api.ts index d0cef1f..5617bea 100644 --- a/src/types/api.ts +++ b/src/types/api.ts @@ -397,6 +397,8 @@ export interface ModelNotification { updated_at?: string url: string verify_tls?: boolean + skip_check?: boolean + format_metric_units?: boolean } export interface ModelNotificationForm { @@ -410,6 +412,8 @@ export interface ModelNotificationForm { skip_check?: boolean url?: string verify_tls?: boolean + skip_check?: boolean + format_metric_units?: boolean } export interface ModelNotificationGroup { @@ -595,6 +599,7 @@ export interface ModelService { enable_trigger_task?: boolean /** 失败时执行的触发任务id */ fail_trigger_tasks: number[] + display_index: number id?: number latency_notify?: boolean max_latency: number @@ -689,6 +694,8 @@ export interface ModelSetting { custom_links?: string background_image_day?: string background_image_night?: string + telegram_bot_token?: string + telegram_admin_chat_id?: string } export interface ModelSettingForm { @@ -722,6 +729,8 @@ export interface ModelSettingForm { background_image_day?: string /** 夜间背景图链接 */ background_image_night?: string + telegram_bot_token?: string + telegram_admin_chat_id?: string } export interface ModelSettingResponse {