fix: 服务发现排除前端已注册的自定义服务

- API 新增 exclude_ports 查询参数,接受逗号分隔端口列表
- 前端 scanServices() 读取 localStorage 自定义服务端口传给后端
- 已添加的服务不再出现在扫描结果中
This commit is contained in:
2026-06-01 18:23:23 +08:00
parent 294526b403
commit ebc8d687d0
2 changed files with 18 additions and 4 deletions

View File

@@ -2886,7 +2886,12 @@
list.innerHTML = '<div class="text-gray-400 text-xs text-center py-2"><i class="ri-loader-4-line animate-spin"></i> 扫描中...</div>';
try {
const res = await fetch('/api/discovery/services');
// 收集前端已注册的自定义服务端口,传给后端排除
const customServices = getCustomServices();
const customPorts = customServices.map(s => parseInt(s.port)).filter(p => !isNaN(p));
const excludeParam = customPorts.length > 0 ? `?exclude_ports=${customPorts.join(',')}` : '';
const res = await fetch(`/api/discovery/services${excludeParam}`);
const data = await res.json();
const services = data.services || [];
document.getElementById('discoveryCount').textContent = `发现 ${services.length} 个`;