update
This commit is contained in:
+150
-1
@@ -1480,4 +1480,153 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
initShieldPage();
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
// ========== 域名信息管理相关功能 ==========
|
||||
|
||||
// 加载远程域名信息列表
|
||||
async function loadRemoteDomainInfoLists() {
|
||||
// 检查是否有有效的缓存数据
|
||||
const cachedDomainInfo = window.pageDataCache && window.pageDataCache.getCache('domain_info_lists');
|
||||
if (cachedDomainInfo) {
|
||||
console.log('使用缓存的域名信息列表');
|
||||
updateDomainInfoListsTable(cachedDomainInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/domain-info');
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`加载失败:${response.status}`);
|
||||
}
|
||||
|
||||
const domainInfo = await response.json();
|
||||
|
||||
// 更新域名信息列表 UI
|
||||
updateDomainInfoListsTable(domainInfo);
|
||||
|
||||
// 存储数据到缓存
|
||||
if (window.pageDataCache) {
|
||||
window.pageDataCache.setCache('domain_info_lists', domainInfo);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('加载域名信息列表失败:', error);
|
||||
showNotification('加载域名信息列表失败', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// 更新域名信息列表表格
|
||||
function updateDomainInfoListsTable(data) {
|
||||
if (!data) return;
|
||||
|
||||
// 更新统计信息
|
||||
if (document.getElementById('domain-info-count')) {
|
||||
document.getElementById('domain-info-count').textContent = data.domainInfoCount || 0;
|
||||
}
|
||||
if (document.getElementById('threat-count')) {
|
||||
document.getElementById('threat-count').textContent = data.threatCount || 0;
|
||||
}
|
||||
if (document.getElementById('tracker-count')) {
|
||||
document.getElementById('tracker-count').textContent = data.trackerCount || 0;
|
||||
}
|
||||
|
||||
// 渲染列表(如果页面有表格元素)
|
||||
if (window.domainInfo && typeof window.domainInfo.renderDomainInfoLists === 'function') {
|
||||
window.domainInfo.renderDomainInfoLists(data);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新所有域名信息
|
||||
async function updateAllDomainInfo() {
|
||||
if (!confirm('确定要更新所有域名信息吗?这可能需要一些时间。')) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/domain-info/update', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`更新失败:${response.status}`);
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.status === 'success') {
|
||||
showNotification('所有域名信息更新任务已启动', 'success');
|
||||
// 清除缓存
|
||||
if (window.pageDataCache) {
|
||||
window.pageDataCache.clearCache('domain_info_lists');
|
||||
}
|
||||
// 延迟刷新
|
||||
setTimeout(() => {
|
||||
loadRemoteDomainInfoLists();
|
||||
}, 2000);
|
||||
} else {
|
||||
showNotification(`更新失败:${result.message || '未知错误'}`, 'error');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('更新所有域名信息失败:', error);
|
||||
showNotification('更新所有域名信息失败', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// 更新指定类型的域名信息
|
||||
async function updateDomainInfoByType(type) {
|
||||
const typeLabels = {
|
||||
'domain-info': '域名信息',
|
||||
'threat-database': '威胁数据库',
|
||||
'tracker': '跟踪器'
|
||||
};
|
||||
|
||||
const typeName = typeLabels[type] || type;
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/domain-info/update/${encodeURIComponent(type)}`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`更新失败:${response.status}`);
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.status === 'success') {
|
||||
showNotification(`${typeName}更新任务已启动`, 'success');
|
||||
// 清除缓存
|
||||
if (window.pageDataCache) {
|
||||
window.pageDataCache.clearCache('domain_info_lists');
|
||||
}
|
||||
// 延迟刷新
|
||||
setTimeout(() => {
|
||||
loadRemoteDomainInfoLists();
|
||||
}, 2000);
|
||||
} else {
|
||||
showNotification(`更新失败:${result.message || '未知错误'}`, 'error');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`更新${typeName}失败:`, error);
|
||||
showNotification(`更新${typeName}失败`, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
// 在 initShieldPage 中添加域名信息列表加载(如果页面存在相关元素)
|
||||
const originalInitShieldPage = window.initShieldPage;
|
||||
window.initShieldPage = async function() {
|
||||
if (originalInitShieldPage) {
|
||||
await originalInitShieldPage();
|
||||
}
|
||||
|
||||
// 如果页面有域名信息管理相关元素,则加载
|
||||
if (document.getElementById('domain-info-lists-table-body')) {
|
||||
await loadRemoteDomainInfoLists();
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user