(e)
| 1688 | } |
| 1689 | |
| 1690 | async function handleSaveCodex2apiService(e) { |
| 1691 | e.preventDefault(); |
| 1692 | const id = document.getElementById('codex2api-service-id').value; |
| 1693 | const name = document.getElementById('codex2api-service-name').value.trim(); |
| 1694 | const apiUrl = document.getElementById('codex2api-service-url').value.trim(); |
| 1695 | const adminKey = document.getElementById('codex2api-service-key').value.trim(); |
| 1696 | const priority = parseInt(document.getElementById('codex2api-service-priority').value) || 0; |
| 1697 | const enabled = document.getElementById('codex2api-service-enabled').checked; |
| 1698 | |
| 1699 | if (!name || !apiUrl) { |
| 1700 | toast.error('名称和 API URL 不能为空'); |
| 1701 | return; |
| 1702 | } |
| 1703 | if (!id && !adminKey) { |
| 1704 | toast.error('新增服务时 Admin Key 不能为空'); |
| 1705 | return; |
| 1706 | } |
| 1707 | |
| 1708 | try { |
| 1709 | const payload = { name, api_url: apiUrl, priority, enabled }; |
| 1710 | if (adminKey) payload.admin_key = adminKey; |
| 1711 | |
| 1712 | if (id) { |
| 1713 | await api.patch(`/codex2api-services/${id}`, payload); |
| 1714 | toast.success('服务已更新'); |
| 1715 | } else { |
| 1716 | await api.post('/codex2api-services', payload); |
| 1717 | toast.success('服务已添加'); |
| 1718 | } |
| 1719 | closeCodex2apiServiceModal(); |
| 1720 | loadCodex2apiServices(); |
| 1721 | } catch (e) { |
| 1722 | toast.error('保存失败: ' + e.message); |
| 1723 | } |
| 1724 | } |
| 1725 | |
| 1726 | async function deleteCodex2apiService(id, name) { |
| 1727 | const confirmed = await confirm(`确定要删除 Codex2API 服务「${name}」吗?`); |
nothing calls this directly
no test coverage detected