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

Method setupInterceptors

frontend/src/utils/request.ts:92–210  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

90 } */
91
92 private setupInterceptors() {
93 // Request interceptor
94 this.instance.interceptors.request.use(
95 async (config: InternalAxiosRequestConfig) => {
96 // Add auth token
97 const token = wsCache.get('user.token')
98 if (token && config.headers) {
99 config.headers['X-SQLBOT-TOKEN'] = `Bearer ${token}`
100 }
101 if (assistantStore.getToken) {
102 const prefix = assistantStore.getType === 4 ? 'Embedded ' : 'Assistant '
103 config.headers['X-SQLBOT-ASSISTANT-TOKEN'] = `${prefix}${assistantStore.getToken}`
104 if (config.headers['X-SQLBOT-TOKEN']) config.headers.delete('X-SQLBOT-TOKEN')
105 if (
106 assistantStore.getType &&
107 !!(assistantStore.getType % 2) &&
108 assistantStore.getCertificate
109 ) {
110 if (
111 /* (config.method?.toLowerCase() === 'get' && /\/chat\/\d+$/.test(config.url || '')) || */
112 /^\/chat/.test(config.url || '') ||
113 config.url?.includes('/system/assistant/ds')
114 ) {
115 await assistantStore.refreshCertificate(config.url || '')
116 }
117 config.headers['X-SQLBOT-ASSISTANT-CERTIFICATE'] = btoa(
118 encodeURIComponent(assistantStore.getCertificate)
119 )
120 }
121 if (!assistantStore.getType || assistantStore.getType === 2) {
122 config.headers['X-SQLBOT-ASSISTANT-ONLINE'] = assistantStore.getOnline
123 }
124 if (assistantStore.getHostOrigin) {
125 config.headers['X-SQLBOT-HOST-ORIGIN'] = assistantStore.getHostOrigin
126 }
127 }
128 const locale = getLocale()
129 if (locale) {
130 /* const mapping = {
131 'zh-CN': 'zh-CN',
132 en: 'en-US',
133 tw: 'zh-TW',
134 } */
135 /* const val = mapping[locale] || locale */
136 config.headers['Accept-Language'] = locale
137 }
138 if (config.url?.includes('/xpack_static/') && config.baseURL) {
139 config.baseURL = config.baseURL.replace('/api/v1', '')
140 // Skip auth for xpack_static requests
141 return config
142 }
143
144 /* try {
145 const request_key = LicenseGenerator.generate()
146 config.headers['X-SQLBOT-KEY'] = request_key
147 } catch (e: any) {
148 if (e?.message?.includes('offline')) {
149 this.cancelCurrentRequest('license-key error detected')

Callers 1

constructorMethod · 0.95

Calls 9

handleErrorMethod · 0.95
getLocaleFunction · 0.90
useMethod · 0.80
replaceMethod · 0.80
requestMethod · 0.80
getMethod · 0.65
deleteMethod · 0.45
includesMethod · 0.45
rejectMethod · 0.45

Tested by

no test coverage detected