| 1749 | } |
| 1750 | |
| 1751 | async function handleTestCodex2apiService() { |
| 1752 | const apiUrl = document.getElementById('codex2api-service-url').value.trim(); |
| 1753 | const adminKey = document.getElementById('codex2api-service-key').value.trim(); |
| 1754 | const id = document.getElementById('codex2api-service-id').value; |
| 1755 | |
| 1756 | if (!apiUrl) { |
| 1757 | toast.error('请先填写 API URL'); |
| 1758 | return; |
| 1759 | } |
| 1760 | if (!id && !adminKey) { |
| 1761 | toast.error('请先填写 Admin Key'); |
| 1762 | return; |
| 1763 | } |
| 1764 | |
| 1765 | elements.testCodex2apiServiceBtn.disabled = true; |
| 1766 | elements.testCodex2apiServiceBtn.textContent = '测试中...'; |
| 1767 | |
| 1768 | try { |
| 1769 | let result; |
| 1770 | if (id && !adminKey) { |
| 1771 | result = await api.post(`/codex2api-services/${id}/test`); |
| 1772 | } else { |
| 1773 | result = await api.post('/codex2api-services/test-connection', { api_url: apiUrl, admin_key: adminKey }); |
| 1774 | } |
| 1775 | if (result.success) { |
| 1776 | toast.success(result.message); |
| 1777 | } else { |
| 1778 | toast.error(result.message); |
| 1779 | } |
| 1780 | } catch (e) { |
| 1781 | toast.error('测试失败: ' + e.message); |
| 1782 | } finally { |
| 1783 | elements.testCodex2apiServiceBtn.disabled = false; |
| 1784 | elements.testCodex2apiServiceBtn.textContent = '🔌 测试连接'; |
| 1785 | } |
| 1786 | } |
| 1787 | |
| 1788 | async function loadNewApiServices() { |
| 1789 | if (!elements.newApiServicesTable) return; |