void;
+ onOk: (data: RateLimit) => void; // Assuming onOk will receive the form data
+}
+
+interface RateLimit {
+ // Omitting some properties for brevity
+ name: string;
+ enable: boolean;
+ endpointWhitelist: string[];
+ clientIdHeader: string;
+ clientWhitelist: string[];
+ realIpHeader: string;
+ ipWhitelist: string[];
+ httpStatusCode: number;
+ quotaExceededMessage: string;
+ rateLimitCounterPrefix: string;
+ enableEndpointRateLimiting: boolean;
+ disableRateLimitHeaders: boolean;
+ enableRegexRuleMatching: boolean;
+ generalRules: GeneralRule[];
+}
+
+interface GeneralRule {
+ endpoint: string;
+ period: string;
+ limit: number;
+}
+
+const { Input, Checkbox, Select,TextArea,InputNumber } = Form;
+
+export default function CreateRateLimitPage({
+ visible,
+ onClose,
+ onOk
+}: ICreateRateLimitProps) {
+
+ function handleSubmit(values: RateLimit) {
+ if (values.generalRules.length === 0) {
+ Notification.error({
+ title: '请添加速率限制规则',
+ });
+ return;
+ }
+
+ CreateRateLimit(values).then(() => {
+ Notification.success({
+ title: '创建成功',
+ });
+ onOk(values);
+ }
+ ).catch(() => {
+ Notification.error({
+ title: '创建失败',
+ });
+ });
+ }
+
+ return (
+
+
+
+ );
+}
\ No newline at end of file
diff --git a/web/src/pages/rate-limit/features/UpdateRateLimit.tsx b/web/src/pages/rate-limit/features/UpdateRateLimit.tsx
new file mode 100644
index 0000000..923a90f
--- /dev/null
+++ b/web/src/pages/rate-limit/features/UpdateRateLimit.tsx
@@ -0,0 +1,286 @@
+import { Button, Collapse, Form, Modal, Notification } from "@douyinfe/semi-ui";
+import { UpdateRateLimit } from "../../../services/RateLimitService";
+
+interface IUpdateRateLimitProps {
+ visible: boolean;
+ onClose: () => void;
+ onOk: (data: RateLimit) => void; // Assuming onOk will receive the form data
+ value:any;
+}
+
+interface RateLimit {
+ // Omitting some properties for brevity
+ name: string;
+ enable: boolean;
+ endpointWhitelist: string[];
+ clientIdHeader: string;
+ clientWhitelist: string[];
+ realIpHeader: string;
+ ipWhitelist: string[];
+ httpStatusCode: number;
+ quotaExceededMessage: string;
+ rateLimitCounterPrefix: string;
+ enableEndpointRateLimiting: boolean;
+ disableRateLimitHeaders: boolean;
+ enableRegexRuleMatching: boolean;
+ generalRules: GeneralRule[];
+}
+
+interface GeneralRule {
+ endpoint: string;
+ period: string;
+ limit: number;
+}
+
+const { Input, Checkbox,TextArea, Select, InputNumber } = Form;
+
+export default function UpdateRateLimitPage({
+ visible,
+ onClose,
+ onOk,
+ value
+}: IUpdateRateLimitProps) {
+
+ function handleSubmit(values: RateLimit) {
+ if (values.generalRules.length === 0) {
+ Notification.error({
+ title: '请添加速率限制规则',
+ });
+ return;
+ }
+
+ UpdateRateLimit(values,values.name).then(() => {
+ Notification.success({
+ title: '创建成功',
+ });
+ onOk(values);
+ }
+ ).catch(() => {
+ Notification.error({
+ title: '创建失败',
+ });
+ });
+ }
+
+ return (
+
+
+
+ );
+}
\ No newline at end of file
diff --git a/web/src/pages/rate-limit/index.tsx b/web/src/pages/rate-limit/index.tsx
new file mode 100644
index 0000000..00cb805
--- /dev/null
+++ b/web/src/pages/rate-limit/index.tsx
@@ -0,0 +1,139 @@
+import { Button, Dropdown, Notification, Table, Tag } from "@douyinfe/semi-ui";
+import { useEffect, useState } from "react";
+import { DeleteRateLimit, GetRateLimit } from "../../services/RateLimitService";
+import CreateRateLimitPage from "./features/CreateRateLimit";
+import UpdateRateLimitPage from "./features/UpdateRateLimit";
+
+
+export default function RateLimit(){
+ const [loading, setLoading] = useState(false);
+ const [data, setData] = useState([]);
+ const [total, setTotal] = useState(0);
+ const [updateVisible, setUpdateVisible] = useState(false);
+ const [updateData, setUpdateData] = useState({} as any);
+ const [createVisible, setCreateVisible] = useState(false);
+ const [input, setInput] = useState({
+ page: 1,
+ pageSize: 10,
+ });
+
+ const columns = [
+ {
+ title: '名称',
+ dataIndex: 'name',
+ key: 'name',
+ },
+ {
+ title: '是否启用',
+ dataIndex: 'enable',
+ key: 'enable',
+ render: (text: boolean) => {
+ return text ?
启用 :
禁用;
+ }
+ },
+ {
+ title: '操作',
+ key: 'action',
+ render: (_text: any, item: any) => (
+
+ 启用/禁用
+ {
+ del(item.name);
+ }}>删除
+ {
+ setUpdateData(item);
+ setUpdateVisible(true);
+ }}>编辑
+
+ }
+ >
+
+
+ )
+ }
+ ]
+
+ function del(name: string){
+ DeleteRateLimit(name).then(() => {
+ setInput({
+ ...input,
+ page: 1,
+ });
+ Notification.success({
+ title: '删除成功',
+ });
+ });
+ }
+
+ function load(){
+ GetRateLimit(input.page, input.pageSize).then(res => {
+ setData(res.items);
+ setTotal(res.total);
+ }).finally(() => {
+ setLoading(false);
+ });
+ }
+
+ useEffect(() => {
+ load();
+ }, [input]);
+
+ return(
+ <>
+
+
+ 限流管理
+
+
+
+
{
+ setInput({
+ ...input,
+ page,
+ pageSize,
+ });
+ }
+ }
+ } />
+ setCreateVisible(false)} onOk={() => {
+ setInput({
+ ...input,
+ page: 1,
+ });
+ setCreateVisible(false);
+ }} />
+ setUpdateVisible(false)} onOk={() => {
+ setInput({
+ ...input,
+ page: 1,
+ });
+ setUpdateVisible(false);
+ }} />
+ >)
+}
\ No newline at end of file
diff --git a/web/src/services/RateLimitService.ts b/web/src/services/RateLimitService.ts
new file mode 100644
index 0000000..147dd33
--- /dev/null
+++ b/web/src/services/RateLimitService.ts
@@ -0,0 +1,22 @@
+import { del, get, postJson, putJson } from "../utils/fetch";
+
+
+export function CreateRateLimit(input: any) {
+ return postJson('/api/v1/RateLimit', input);
+}
+
+export function UpdateRateLimit(input: any,name:string) {
+ return putJson('/api/v1/RateLimit/'+name, input);
+}
+
+export function DeleteRateLimit(name: string) {
+ return del('/api/v1/RateLimit/'+name);
+}
+
+export function GetRateLimit(page: number, pageSize: number) {
+ return get('/api/v1/RateLimit/List?page=' + page + '&pageSize=' + pageSize);
+}
+
+export function GetNames(){
+ return get('/api/v1/RateLimit/Names');
+}
\ No newline at end of file
From 4aab75537f5cd1f23d3ec0126ca9a2669fe16d11 Mon Sep 17 00:00:00 2001
From: token <239573049@qq.com>
Date: Thu, 11 Apr 2024 19:17:49 +0800
Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8F=8F=E8=BF=B0?=
=?UTF-8?q?=E5=92=8C=E6=AD=A3=E5=88=99=E8=A1=A8=E8=BE=BE=E5=BC=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
web/src/pages/rate-limit/features/CreateRateLimit.tsx | 4 ++--
web/src/pages/rate-limit/features/UpdateRateLimit.tsx | 6 ++----
2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/web/src/pages/rate-limit/features/CreateRateLimit.tsx b/web/src/pages/rate-limit/features/CreateRateLimit.tsx
index 10e5609..77d27e2 100644
--- a/web/src/pages/rate-limit/features/CreateRateLimit.tsx
+++ b/web/src/pages/rate-limit/features/CreateRateLimit.tsx
@@ -229,7 +229,7 @@ export default function CreateRateLimitPage({
]}
/>