MCPcopy Create free account
hub / github.com/Tron521/codex-console-temp / handleSaveCpaService

Function handleSaveCpaService

static/js/settings.js:1367–1403  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

1365}
1366
1367async function handleSaveCpaService(e) {
1368 e.preventDefault();
1369 const id = document.getElementById('cpa-service-id').value;
1370 const name = document.getElementById('cpa-service-name').value.trim();
1371 const apiUrl = document.getElementById('cpa-service-url').value.trim();
1372 const apiToken = document.getElementById('cpa-service-token').value.trim();
1373 const proxyUrl = document.getElementById('cpa-service-proxy-url').value.trim();
1374 const priority = parseInt(document.getElementById('cpa-service-priority').value) || 0;
1375 const enabled = document.getElementById('cpa-service-enabled').checked;
1376
1377 if (!name || !apiUrl) {
1378 toast.error('名称和 API URL 不能为空');
1379 return;
1380 }
1381 if (!id && !apiToken) {
1382 toast.error('新增服务时 API Token 不能为空');
1383 return;
1384 }
1385
1386 try {
1387 const payload = { name, api_url: apiUrl, proxy_url: proxyUrl, priority, enabled };
1388 if (apiToken) payload.api_token = apiToken;
1389
1390 if (id) {
1391 await api.patch(`/cpa-services/${id}`, payload);
1392 toast.success('服务已更新');
1393 } else {
1394 payload.api_token = apiToken;
1395 await api.post('/cpa-services', payload);
1396 toast.success('服务已添加');
1397 }
1398 closeCpaServiceModal();
1399 loadCpaServices();
1400 } catch (e) {
1401 toast.error('保存失败: ' + e.message);
1402 }
1403}
1404
1405async function deleteCpaService(id, name) {
1406 const confirmed = await confirm(`确定要删除 CPA 服务「${name}」吗?`);

Callers

nothing calls this directly

Calls 6

closeCpaServiceModalFunction · 0.85
loadCpaServicesFunction · 0.85
errorMethod · 0.80
successMethod · 0.80
patchMethod · 0.45
postMethod · 0.45

Tested by

no test coverage detected