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

Method fetchStream

frontend/src/utils/request.ts:307–354  ·  view source on GitHub ↗
(url: string, data?: any, controller?: AbortController)

Source from the content-addressed store, hash-verified

305 }
306
307 public async fetchStream(url: string, data?: any, controller?: AbortController): Promise<any> {
308 const token = wsCache.get('user.token')
309 const heads: any = {
310 'Content-Type': 'application/json',
311 }
312 if (token) {
313 heads['X-SQLBOT-TOKEN'] = `Bearer ${token}`
314 }
315 if (assistantStore.getToken) {
316 const prefix = assistantStore.getType === 4 ? 'Embedded ' : 'Assistant '
317 heads['X-SQLBOT-ASSISTANT-TOKEN'] = `${prefix}${assistantStore.getToken}`
318 if (heads['X-SQLBOT-TOKEN']) delete heads['X-SQLBOT-TOKEN']
319 if (
320 assistantStore.getType &&
321 !!(assistantStore.getType % 2) &&
322 assistantStore.getCertificate
323 ) {
324 await assistantStore.refreshCertificate(url)
325 heads['X-SQLBOT-ASSISTANT-CERTIFICATE'] = btoa(
326 encodeURIComponent(assistantStore.getCertificate)
327 )
328 }
329 if (assistantStore.getHostOrigin) {
330 heads['X-SQLBOT-HOST-ORIGIN'] = assistantStore.getHostOrigin
331 }
332 if (!assistantStore.getType || assistantStore.getType === 2) {
333 heads['X-SQLBOT-ASSISTANT-ONLINE'] = assistantStore.getOnline
334 }
335 }
336
337 /* try {
338 const request_key = LicenseGenerator.generate()
339 heads['X-SQLBOT-KEY'] = request_key
340 } catch (e: any) {
341 if (e?.message?.includes('offline')) {
342 controller?.abort('license-key error detected')
343 showLicenseKeyError()
344 }
345 } */
346
347 const real_url = import.meta.env.VITE_API_BASE_URL
348 return fetch(real_url + url, {
349 method: 'POST',
350 headers: heads,
351 body: JSON.stringify(data),
352 signal: controller?.signal,
353 })
354 }
355
356 // PUT request
357 public put<T = any>(url: string, data?: any, config?: FullRequestConfig): Promise<T> {

Callers 2

system.tsFile · 0.80
chat.tsFile · 0.80

Calls 1

getMethod · 0.65

Tested by

no test coverage detected