(src, id)
| 563 | }) |
| 564 | } |
| 565 | function loadScript(src, id) { |
| 566 | const domain_url = getDomain(src) |
| 567 | const online = getParam(src, 'online') |
| 568 | const userFlag = getParam(src, 'userFlag') |
| 569 | const history = getParam(src, 'history') |
| 570 | let url = `${domain_url}/api/v1/system/assistant/info/${id}` |
| 571 | if (domain_url.includes('5173')) { |
| 572 | url = url.replace('5173', '8000') |
| 573 | } |
| 574 | fetch(url) |
| 575 | .then((response) => response.json()) |
| 576 | .then((res) => { |
| 577 | if (!res.data) { |
| 578 | throw new Error(res) |
| 579 | } |
| 580 | const data = res.data |
| 581 | const config_json = data.configuration |
| 582 | let tempData = Object.assign(defaultData, data) |
| 583 | if (tempData.configuration) { |
| 584 | delete tempData.configuration |
| 585 | } |
| 586 | if (config_json) { |
| 587 | const config = JSON.parse(config_json) |
| 588 | if (config) { |
| 589 | delete config.id |
| 590 | tempData = Object.assign(tempData, config) |
| 591 | } |
| 592 | } |
| 593 | tempData['id'] = id |
| 594 | tempData['domain_url'] = domain_url |
| 595 | |
| 596 | if (tempData['float_icon'] && !tempData['float_icon'].startsWith('http://')) { |
| 597 | tempData['float_icon'] = |
| 598 | `${domain_url}/api/v1/system/assistant/picture/${tempData['float_icon']}` |
| 599 | |
| 600 | if (domain_url.includes('5173')) { |
| 601 | tempData['float_icon'] = tempData['float_icon'].replace('5173', '8000') |
| 602 | } |
| 603 | } |
| 604 | |
| 605 | tempData['online'] = online && online.toString().toLowerCase() == 'true' |
| 606 | tempData['userFlag'] = userFlag |
| 607 | tempData['history'] = history |
| 608 | initsqlbot_assistant(tempData) |
| 609 | registerMessageEvent(id, tempData) |
| 610 | }) |
| 611 | .catch((e) => { |
| 612 | showMsg('嵌入失败', e.message) |
| 613 | }) |
| 614 | } |
| 615 | function getDomain(src) { |
| 616 | return src.substring(0, src.indexOf('/assistant.js')) |
| 617 | } |
no test coverage detected