浏览代码

Fix: Stash Hosts

SukkaW 10 月之前
父节点
当前提交
67b7c0b0d7
共有 1 个文件被更改,包括 16 次插入2 次删除
  1. 16 2
      Build/build-domestic-direct-lan-ruleset-dns-mapping-module.ts

+ 16 - 2
Build/build-domestic-direct-lan-ruleset-dns-mapping-module.ts

@@ -194,7 +194,7 @@ export const buildDomesticRuleset = task(require.main === module, __filename)(as
       yaml.stringify(
         dataset.reduce<{
           dns: { 'nameserver-policy': Record<string, string | string[]> },
-          hosts: Record<string, string>
+          hosts: Record<string, string | string[]>
         }>((acc, cur) => {
           const { domains, dns, ...rest } = cur[1];
           domains.forEach((domain) => {
@@ -216,7 +216,21 @@ export const buildDomesticRuleset = task(require.main === module, __filename)(as
           });
 
           if ('hosts' in rest) {
-            Object.assign(acc.hosts, rest.hosts);
+            // eslint-disable-next-line guard-for-in -- known plain object
+            for (const domain in rest.hosts) {
+              const dest = rest.hosts[domain];
+
+              if (domain in acc.hosts) {
+                if (typeof acc.hosts[domain] === 'string') {
+                  acc.hosts[domain] = [acc.hosts[domain]];
+                }
+                acc.hosts[domain].push(...dest);
+              } else if (dest.length === 1) {
+                acc.hosts[domain] = dest[0];
+              } else {
+                acc.hosts[domain] = dest;
+              }
+            }
           }
 
           return acc;