优化日志详情域名信息显示

This commit is contained in:
Alex Yang
2025-12-30 15:17:49 +08:00
parent 97413e88f0
commit 2524336bab
4 changed files with 632 additions and 67 deletions

View File

@@ -169,47 +169,95 @@ async function getDomainInfo(domain) {
const companyData = domainInfoDatabase.domains[companyKey];
const companyName = companyData.company || companyKey;
// 遍历公司下的所有网站
// 遍历公司下的所有网站和类别
for (const websiteKey in companyData) {
if (companyData.hasOwnProperty(websiteKey) && websiteKey !== 'company') {
console.log(' 检查网站:', websiteKey);
console.log(' 检查网站/类别:', websiteKey);
const website = companyData[websiteKey];
// 检查域名是否匹配网站的URL
// 如果有URL属性直接检查域名
if (website.url) {
// 处理字符串类型的URL
if (typeof website.url === 'string') {
console.log(' 检查字符串URL:', website.url);
if (isDomainMatch(website.url, normalizedDomain)) {
console.log(' 匹配成功,返回网站信息');
return {
name: website.name,
icon: website.icon,
categoryId: website.categoryId,
categoryName: domainInfoDatabase.categories[website.categoryId] || '未知',
company: companyName
};
if (typeof website.url === 'string') {
console.log(' 检查字符串URL:', website.url);
if (isDomainMatch(website.url, normalizedDomain, website.categoryId)) {
console.log(' 匹配成功,返回网站信息');
return {
name: website.name,
icon: website.icon,
categoryId: website.categoryId,
categoryName: domainInfoDatabase.categories[website.categoryId] || '未知',
company: website.company || companyName
};
}
}
}
// 处理对象类型的URL
else if (typeof website.url === 'object') {
console.log(' 检查对象类型URL包含', Object.keys(website.url).length, '个URL');
for (const urlKey in website.url) {
if (website.url.hasOwnProperty(urlKey)) {
const urlValue = website.url[urlKey];
console.log(' 检查URL', urlKey, ':', urlValue);
if (isDomainMatch(urlValue, normalizedDomain)) {
console.log(' 匹配成功,返回网站信息');
return {
name: website.name,
icon: website.icon,
categoryId: website.categoryId,
categoryName: domainInfoDatabase.categories[website.categoryId] || '未知',
company: companyName
};
// 处理对象类型的URL
else if (typeof website.url === 'object') {
console.log(' 检查对象类型URL包含', Object.keys(website.url).length, '个URL');
for (const urlKey in website.url) {
if (website.url.hasOwnProperty(urlKey)) {
const urlValue = website.url[urlKey];
console.log(' 检查URL', urlKey, ':', urlValue);
if (isDomainMatch(urlValue, normalizedDomain, website.categoryId)) {
console.log(' 匹配成功,返回网站信息');
return {
name: website.name,
icon: website.icon,
categoryId: website.categoryId,
categoryName: domainInfoDatabase.categories[website.categoryId] || '未知',
company: website.company || companyName
};
}
}
}
}
} else if (typeof website === 'object' && website !== null) {
// 没有URL属性可能是嵌套的类别
console.log(' 发现嵌套类别,进一步检查');
for (const nestedWebsiteKey in website) {
if (website.hasOwnProperty(nestedWebsiteKey) && nestedWebsiteKey !== 'company') {
console.log(' 检查嵌套网站:', nestedWebsiteKey);
const nestedWebsite = website[nestedWebsiteKey];
if (nestedWebsite.url) {
// 处理字符串类型的URL
if (typeof nestedWebsite.url === 'string') {
console.log(' 检查字符串URL:', nestedWebsite.url);
if (isDomainMatch(nestedWebsite.url, normalizedDomain, nestedWebsite.categoryId)) {
console.log(' 匹配成功,返回网站信息');
return {
name: nestedWebsite.name,
icon: nestedWebsite.icon,
categoryId: nestedWebsite.categoryId,
categoryName: domainInfoDatabase.categories[nestedWebsite.categoryId] || '未知',
company: nestedWebsite.company || companyName
};
}
}
// 处理对象类型的URL
else if (typeof nestedWebsite.url === 'object') {
console.log(' 检查对象类型URL包含', Object.keys(nestedWebsite.url).length, '个URL');
for (const urlKey in nestedWebsite.url) {
if (nestedWebsite.url.hasOwnProperty(urlKey)) {
const urlValue = nestedWebsite.url[urlKey];
console.log(' 检查URL', urlKey, ':', urlValue);
if (isDomainMatch(urlValue, normalizedDomain, nestedWebsite.categoryId)) {
console.log(' 匹配成功,返回网站信息');
return {
name: nestedWebsite.name,
icon: nestedWebsite.icon,
categoryId: nestedWebsite.categoryId,
categoryName: domainInfoDatabase.categories[nestedWebsite.categoryId] || '未知',
company: nestedWebsite.company || companyName
};
}
}
}
}
} else {
console.log(' 嵌套网站没有URL属性');
}
}
}
} else {
console.log(' 网站没有URL属性');
@@ -224,8 +272,8 @@ async function getDomainInfo(domain) {
}
// 检查域名是否匹配
function isDomainMatch(urlValue, targetDomain) {
console.log(' 开始匹配URL:', urlValue, '目标域名:', targetDomain);
function isDomainMatch(urlValue, targetDomain, categoryId) {
console.log(' 开始匹配URL:', urlValue, '目标域名:', targetDomain, '类别ID:', categoryId);
try {
// 尝试将URL值解析为完整URL
@@ -234,14 +282,25 @@ function isDomainMatch(urlValue, targetDomain) {
const hostname = url.hostname.toLowerCase();
console.log(' 解析成功,主机名:', hostname);
// 只匹配完整域名,不进行主域名匹配
// 这是为了避免同一个公司下的不同网站(如微信和腾讯视频)因为主域名相同而错误匹配
if (hostname === targetDomain) {
console.log(' 完整域名匹配成功');
return true;
// 根据类别ID选择匹配方式
if (categoryId === 2) {
// CDN类别使用域名后缀匹配
if (targetDomain.endsWith('.' + hostname) || targetDomain === hostname) {
console.log(' CDN域名后缀匹配成功');
return true;
} else {
console.log(' CDN域名后缀不匹配');
return false;
}
} else {
console.log(' 完整域名匹配');
return false;
// 其他类别,使用完整域名匹配
if (hostname === targetDomain) {
console.log(' 完整域名匹配成功');
return true;
} else {
console.log(' 完整域名不匹配');
return false;
}
}
} catch (e) {
console.log(' 解析URL失败将其视为纯域名处理错误信息:', e.message);
@@ -249,13 +308,25 @@ function isDomainMatch(urlValue, targetDomain) {
const urlDomain = urlValue.toLowerCase();
console.log(' 处理为纯域名:', urlDomain);
// 只匹配完整域名,不进行主域名匹配
if (urlDomain === targetDomain) {
console.log(' 完整域名匹配成功');
return true;
// 根据类别ID选择匹配方式
if (categoryId === 2) {
// CDN类别使用域名后缀匹配
if (targetDomain.endsWith('.' + urlDomain) || targetDomain === urlDomain) {
console.log(' CDN域名后缀匹配成功');
return true;
} else {
console.log(' CDN域名后缀不匹配');
return false;
}
} else {
console.log(' 完整域名匹配');
return false;
// 其他类别,使用完整域名匹配
if (urlDomain === targetDomain) {
console.log(' 完整域名匹配成功');
return true;
} else {
console.log(' 完整域名不匹配');
return false;
}
}
}
}