This commit is contained in:
Alex Yang
2025-11-24 23:50:29 +08:00
parent 87143a77b9
commit 9f81b449f1
2 changed files with 159 additions and 7 deletions

View File

@@ -40,11 +40,20 @@ async function loadRules() {
const rulesPanel = document.getElementById('rules-panel');
showLoading(rulesPanel);
// 更新API路径使用完整路径
// 更新API路径使用正确的API路径
const data = await apiRequest('/shield', 'GET');
// 处理不同格式的响应数据
rules = Array.isArray(data) ? data : (data.rules || []);
// 处理后端返回的复杂对象数据格式
let allRules = [];
if (data && typeof data === 'object') {
// 合并所有类型的规则到一个数组
if (Array.isArray(data.domainRules)) allRules = allRules.concat(data.domainRules);
if (Array.isArray(data.domainExceptions)) allRules = allRules.concat(data.domainExceptions);
if (Array.isArray(data.regexRules)) allRules = allRules.concat(data.regexRules);
if (Array.isArray(data.regexExceptions)) allRules = allRules.concat(data.regexExceptions);
}
rules = allRules;
filteredRules = [...rules];
currentPage = 1; // 重置为第一页
renderRulesList();
@@ -197,7 +206,7 @@ async function addNewRule() {
// 预处理规则支持AdGuardHome格式
const processedRule = preprocessRule(rule);
// 更新API路径
// 使用正确的API路径
const response = await apiRequest('/shield', 'POST', { rule: processedRule });
// 处理不同的响应格式
@@ -248,7 +257,7 @@ async function deleteRule(index) {
rowElement.style.transform = 'translateX(-20px)';
}
// 更新API路径
// 使用正确的API路径
const response = await apiRequest('/shield', 'DELETE', { rule });
// 处理不同的响应格式
@@ -310,8 +319,8 @@ async function reloadRules() {
const rulesPanel = document.getElementById('rules-panel');
showLoading(rulesPanel);
// 确保使用正确的API路径
await apiRequest('/shield/refresh', 'POST');
// 使用正确的API路径和方法 - PUT请求到/shield
await apiRequest('/shield', 'PUT');
// 重新加载规则列表
await loadRules();