Skip to content

Commit 4d5744a

Browse files
authored
feat: support delete all stream routes (#3119)
1 parent 9085c80 commit 4d5744a

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/apis/stream_routes.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@
1818
import type { AxiosInstance } from 'axios';
1919

2020
import type { StreamRoutePostType } from '@/components/form-slice/FormPartStreamRoute/schema';
21-
import { API_STREAM_ROUTES } from '@/config/constant';
21+
import {
22+
API_STREAM_ROUTES,
23+
PAGE_SIZE_MAX,
24+
PAGE_SIZE_MIN,
25+
} from '@/config/constant';
2226
import type { APISIXType } from '@/types/schema/apisix';
2327

2428
import type { WithServiceIdFilter } from './routes';
@@ -59,3 +63,21 @@ export const postStreamRouteReq = (
5963
API_STREAM_ROUTES,
6064
data
6165
);
66+
67+
export const deleteAllStreamRoutes = async (req: AxiosInstance) => {
68+
const totalRes = await getStreamRouteListReq(req, {
69+
page: 1,
70+
page_size: PAGE_SIZE_MIN,
71+
});
72+
const total = totalRes.total;
73+
if (total === 0) return;
74+
for (let times = Math.ceil(total / PAGE_SIZE_MAX); times > 0; times--) {
75+
const res = await getStreamRouteListReq(req, {
76+
page: 1,
77+
page_size: PAGE_SIZE_MAX,
78+
});
79+
await Promise.all(
80+
res.list.map((d) => req.delete(`${API_STREAM_ROUTES}/${d.value.id}`))
81+
);
82+
}
83+
};

0 commit comments

Comments
 (0)