feat: decouple speed limits from tunnels and add forward-level rate limiting

- Make SpeedLimit.TunnelID and TunnelName nullable (optional binding)
- Add SpeedID field to Forward model for forward-level rate limiting
- Update ForwardRecord to include SpeedID for control plane
- Update repository methods to handle optional tunnel binding
- Update handlers to accept optional tunnelId in create/update
- Modify control plane to prioritize Forward.SpeedID over UserTunnel speed limit
- Update frontend limit.tsx to support creating speed limits without tunnel binding
- Update TypeScript types for optional tunnelId and new speedId fields

This allows speed limits to be created as reusable rules that can be applied
to either tunnels (via UserTunnel.SpeedID) or individual forwards (via Forward.SpeedID).
This commit is contained in:
sagitchu
2026-02-26 13:08:35 +08:00
parent 4bdfa50b0c
commit c8eb780c67
11 changed files with 318 additions and 89 deletions
+4 -2
View File
@@ -51,6 +51,7 @@ export interface ForwardApiItem {
outFlow?: number;
userId?: number;
tunnelId?: number;
speedId?: number | null;
inx?: number;
[key: string]: unknown;
}
@@ -96,10 +97,10 @@ export interface StatisticsFlowApiItem {
export interface SpeedLimitApiItem {
id: number;
name: string;
tunnelId: number;
tunnelId?: number | null;
speed: number;
status: number;
tunnelName: string;
tunnelName?: string;
createdTime: string;
updatedTime: string;
uploadSpeed?: number;
@@ -284,6 +285,7 @@ export interface ForwardMutationPayload {
inPort?: number | null;
remoteAddr?: string;
strategy?: string;
speedId?: number | null;
}
export interface SpeedLimitMutationPayload {