(e)
| 1842 | } |
| 1843 | |
| 1844 | async function handleSaveNewApiService(e) { |
| 1845 | e.preventDefault(); |
| 1846 | const id = document.getElementById('new-api-service-id').value; |
| 1847 | const name = document.getElementById('new-api-service-name').value.trim(); |
| 1848 | const apiUrl = document.getElementById('new-api-service-url').value.trim(); |
| 1849 | const username = document.getElementById('new-api-service-username').value.trim(); |
| 1850 | const password = document.getElementById('new-api-service-password').value.trim(); |
| 1851 | const priority = parseInt(document.getElementById('new-api-service-priority').value) || 0; |
| 1852 | const enabled = document.getElementById('new-api-service-enabled').checked; |
| 1853 | |
| 1854 | if (!name || !apiUrl || !username) { |
| 1855 | toast.error('名称、API URL 和管理员用户名不能为空'); |
| 1856 | return; |
| 1857 | } |
| 1858 | if (!id && !password) { |
| 1859 | toast.error('新增服务时管理员密码不能为空'); |
| 1860 | return; |
| 1861 | } |
| 1862 | |
| 1863 | try { |
| 1864 | const payload = { name, api_url: apiUrl, username, priority, enabled }; |
| 1865 | if (password) payload.password = password; |
| 1866 | |
| 1867 | if (id) { |
| 1868 | await api.patch(`/new-api-services/${id}`, payload); |
| 1869 | toast.success('服务已更新'); |
| 1870 | } else { |
| 1871 | await api.post('/new-api-services', payload); |
| 1872 | toast.success('服务已添加'); |
| 1873 | } |
| 1874 | closeNewApiServiceModal(); |
| 1875 | loadNewApiServices(); |
| 1876 | } catch (e) { |
| 1877 | toast.error('保存失败: ' + e.message); |
| 1878 | } |
| 1879 | } |
| 1880 | |
| 1881 | async function deleteNewApiService(id, name) { |
| 1882 | const confirmed = await confirm(`确定要删除 new-api 服务「${name}」吗?`); |
nothing calls this directly
no test coverage detected