| 1596 | } |
| 1597 | |
| 1598 | async function handleTestSub2ApiService() { |
| 1599 | const apiUrl = document.getElementById('sub2api-service-url').value.trim(); |
| 1600 | const apiKey = document.getElementById('sub2api-service-key').value.trim(); |
| 1601 | const id = document.getElementById('sub2api-service-id').value; |
| 1602 | |
| 1603 | if (!apiUrl) { |
| 1604 | toast.error('请先填写 API URL'); |
| 1605 | return; |
| 1606 | } |
| 1607 | if (!id && !apiKey) { |
| 1608 | toast.error('请先填写 API Key'); |
| 1609 | return; |
| 1610 | } |
| 1611 | |
| 1612 | elements.testSub2ApiServiceBtn.disabled = true; |
| 1613 | elements.testSub2ApiServiceBtn.textContent = '测试中...'; |
| 1614 | |
| 1615 | try { |
| 1616 | let result; |
| 1617 | if (id && !apiKey) { |
| 1618 | result = await api.post(`/sub2api-services/${id}/test`); |
| 1619 | } else { |
| 1620 | result = await api.post('/sub2api-services/test-connection', { api_url: apiUrl, api_key: apiKey }); |
| 1621 | } |
| 1622 | if (result.success) { |
| 1623 | toast.success(result.message); |
| 1624 | } else { |
| 1625 | toast.error(result.message); |
| 1626 | } |
| 1627 | } catch (e) { |
| 1628 | toast.error('测试失败: ' + e.message); |
| 1629 | } finally { |
| 1630 | elements.testSub2ApiServiceBtn.disabled = false; |
| 1631 | elements.testSub2ApiServiceBtn.textContent = '🔌 测试连接'; |
| 1632 | } |
| 1633 | } |
| 1634 | |
| 1635 | async function loadCodex2apiServices() { |
| 1636 | if (!elements.codex2apiServicesTable) return; |