diff --git a/package.json b/package.json index b71a163..6d47d84 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lanhu-admin", - "version": "1.7.0", + "version": "1.8.0", "private": true, "scripts": { "dev": "next dev -H 0.0.0.0 -p 3001 --turbopack", diff --git a/src/actions/gateway.ts b/src/actions/gateway.ts index 7e28f27..25f3d0e 100644 --- a/src/actions/gateway.ts +++ b/src/actions/gateway.ts @@ -22,3 +22,7 @@ export async function createGateway(data: { export async function updateGateway(data: { id: number; status: number }) { return callByUser("/api/admin/proxy/update/status", data) } + +export async function clear(data: { proxy_id: number }) { + return callByUser("/api/admin/channel/sync/clear-expired", data) +} diff --git a/src/app/(root)/gateway/page.tsx b/src/app/(root)/gateway/page.tsx index 63d789c..26352a0 100644 --- a/src/app/(root)/gateway/page.tsx +++ b/src/app/(root)/gateway/page.tsx @@ -3,12 +3,12 @@ import { format } from "date-fns" import { Suspense, useCallback, useState } from "react" import { toast } from "sonner" -import { getGatewayPage, updateGateway } from "@/actions/gateway" +import { clear, getGatewayPage, updateGateway } from "@/actions/gateway" import { Auth } from "@/components/auth" import { DataTable, useDataTable } from "@/components/data-table" import { Page } from "@/components/page" import { Button } from "@/components/ui/button" -import { ScopeProxyWrite } from "@/lib/scopes" +import { ScopeChannelWriteClearExpired, ScopeProxyWrite } from "@/lib/scopes" import type { Gateway } from "@/models/gateway" import CreatePage from "./create" @@ -41,15 +41,38 @@ export default function GatewayPage() { setLoading(false) } } + + const clearExpired = async (val: Gateway) => { + setLoading(true) + try { + const result = await clear({ + proxy_id: val.id, + }) + + if (result.success) { + const count = + result.data && "count" in result.data ? result.data.count : 0 + toast.success(`清理过期连接成功,共 ${count} 条`) + } else { + toast.error(result.message || "清理过期连接失败,请稍后重试一下~") + } + } catch (error) { + const message = error instanceof Error ? error.message : error + toast.error(`清理过期连接失败: ${message}`) + } finally { + setLoading(false) + } + } + return ( - -
-
+
+
+ -
+
- +
{...table} @@ -101,6 +124,11 @@ export default function GatewayPage() { > {row.original.status === 0 ? "启用" : "停用"} + + +
), }, diff --git a/src/lib/scopes.ts b/src/lib/scopes.ts index 66fb4c7..8bf26ff 100644 --- a/src/lib/scopes.ts +++ b/src/lib/scopes.ts @@ -91,3 +91,4 @@ export const ScopeProxy = "proxy" export const ScopeProxyRead = "proxy:read" // 读取代理列表 export const ScopeProxyWrite = "proxy:write" // 写入代理 export const ScopeProxyWriteStatus = "proxy:write:status" // 更改代理状态 +export const ScopeChannelWriteClearExpired = "channel:write:clear_expired" //清理过期连接