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

Method loadRemoteScript

frontend/src/utils/request.ts:399–428  ·  view source on GitHub ↗
(url: string, id?: string, cb?: any)

Source from the content-addressed store, hash-verified

397 }
398
399 public loadRemoteScript(url: string, id?: string, cb?: any): Promise<HTMLElement> {
400 if (!url) {
401 return Promise.reject(new Error('URL is required to load remote script'))
402 }
403 if (id && document.getElementById(id)) {
404 return Promise.resolve(document.getElementById(id) as HTMLElement)
405 }
406 if (url.startsWith('/')) {
407 const real_url = import.meta.env.VITE_API_BASE_URL.replace('/api/v1', '')
408 url = real_url + url
409 }
410 return new Promise<HTMLElement>((resolve, reject) => {
411 // 改用传统的script标签加载方式
412 const script = document.createElement('script')
413 script.src = url
414 script.id = id || `remote-script-${Date.now()}`
415
416 script.onload = () => {
417 if (cb) cb()
418 resolve(script)
419 }
420
421 script.onerror = (error) => {
422 console.error(`Failed to load script from ${url}:`, error)
423 reject(new Error(`Failed to load script from ${url}`))
424 }
425
426 document.head.appendChild(script)
427 })
428 }
429 /* public loadRemoteScript(url: string, id?: string, cb?: any): Promise<HTMLElement> {
430 if (!url) {
431 return Promise.reject(new Error('URL is required to load remote script'))

Callers 1

loadXpackStaticFunction · 0.80

Calls 6

resolveFunction · 0.85
resolveMethod · 0.80
replaceMethod · 0.80
errorMethod · 0.80
cbFunction · 0.50
rejectMethod · 0.45

Tested by

no test coverage detected