MCPcopy Index your code
hub / github.com/dataease/SQLBot / watchRouter

Function watchRouter

frontend/src/router/watch.ts:17–66  ·  view source on GitHub ↗
(router: Router)

Source from the content-addressed store, hash-verified

15
16const wsAdminRouterList = ['/ds/index', '/as/index']
17export const watchRouter = (router: Router) => {
18 router.beforeEach(async (to: any, from: any, next: any) => {
19 await loadXpackStatic()
20 await appearanceStore.setAppearance()
21 LicenseGenerator.generateRouters(router)
22 if (to.path.startsWith('/login') && userStore.getUid) {
23 next(to?.query?.redirect || '/')
24 return
25 }
26 if (assistantWhiteList.includes(to.path)) {
27 next()
28 return
29 }
30 const token = wsCache.get('user.token')
31 if (whiteList.includes(to.path)) {
32 next()
33 return
34 }
35 if (!token) {
36 // ElMessage.error('Please login first')
37 next(toLoginPage(to.fullPath))
38 return
39 }
40 if (!userStore.getUid) {
41 await userStore.info()
42 generateDynamicRouters(router)
43 const isFirstDynamicPath = to?.path && ['/ds/index', '/as/index'].includes(to.path)
44 if (isFirstDynamicPath) {
45 if (userStore.isSpaceAdmin) {
46 next({ ...to, replace: true })
47 return
48 }
49 }
50 }
51 if (to.path === '/docs') {
52 location.href = to.fullPath
53 return
54 }
55 if (to.path === '/' || accessCrossPermission(to)) {
56 next('/chat')
57 return
58 }
59 if (to.path === '/login' || to.path === '/admin-login') {
60 console.info(from)
61 next('/chat')
62 } else {
63 next()
64 }
65 })
66}
67
68const accessCrossPermission = (to: any) => {
69 if (!to?.path) return false

Callers 1

index.tsFile · 0.90

Calls 8

toLoginPageFunction · 0.90
generateDynamicRoutersFunction · 0.90
loadXpackStaticFunction · 0.85
nextFunction · 0.85
accessCrossPermissionFunction · 0.85
getMethod · 0.65
includesMethod · 0.45
infoMethod · 0.45

Tested by

no test coverage detected