(router: Router, invalid_router_name_list: string[])
| 45 | ] as any[] |
| 46 | |
| 47 | const reduceRouters = (router: Router, invalid_router_name_list: string[]) => { |
| 48 | const tree = router.getRoutes() |
| 49 | const invalid_name_set = [] as any |
| 50 | invalid_router_name_list.forEach((router_name: string) => { |
| 51 | router.removeRoute(router_name) |
| 52 | invalid_name_set.push(router_name) |
| 53 | }) |
| 54 | |
| 55 | const pathsSet = new Set(invalid_router_name_list) |
| 56 | |
| 57 | function processNode(node: any): boolean { |
| 58 | if (node.name && pathsSet.has(node.name)) { |
| 59 | return true |
| 60 | } |
| 61 | if (node.children) { |
| 62 | const newChildren: any[] = [] |
| 63 | |
| 64 | for (const child of node.children) { |
| 65 | const shouldRemove = processNode(child) |
| 66 | if (!shouldRemove) { |
| 67 | newChildren.push(child) |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | if (newChildren.length > 0) { |
| 72 | node.children = newChildren |
| 73 | return false |
| 74 | } else { |
| 75 | node.children = undefined |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | return false |
| 80 | } |
| 81 | |
| 82 | let i = 0 |
| 83 | while (i < tree.length) { |
| 84 | if (processNode(tree[i])) { |
| 85 | tree.splice(i, 1) |
| 86 | } else { |
| 87 | i++ |
| 88 | } |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | export const generateDynamicRouters = (router: Router) => { |
| 93 | if (userStore.isAdmin || userStore.isSpaceAdmin) { |
no test coverage detected