mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-28 17:41:54 +08:00
Chore: auto build microsoft_cdn
This commit is contained in:
@@ -1,21 +0,0 @@
|
|||||||
import path from 'path';
|
|
||||||
import fsp from 'fs/promises';
|
|
||||||
import { parseFelixDnsmasq } from './lib/parse-dnsmasq';
|
|
||||||
import { task } from './lib/trace-runner';
|
|
||||||
import { compareAndWriteFile } from './lib/create-file';
|
|
||||||
|
|
||||||
export const buildInternalChnDomains = task(import.meta.path, async () => {
|
|
||||||
const result = (await Promise.all([
|
|
||||||
parseFelixDnsmasq('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/accelerated-domains.china.conf'),
|
|
||||||
fsp.mkdir(path.resolve(import.meta.dir, '../List/internal'), { recursive: true })
|
|
||||||
]))[0];
|
|
||||||
|
|
||||||
return compareAndWriteFile(
|
|
||||||
result.map(line => `SUFFIX,${line}`),
|
|
||||||
path.resolve(import.meta.dir, '../List/internal/accelerated-china-domains.txt')
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (import.meta.main) {
|
|
||||||
buildInternalChnDomains();
|
|
||||||
}
|
|
||||||
63
Build/build-microsoft-cdn.ts
Normal file
63
Build/build-microsoft-cdn.ts
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
import path from 'path';
|
||||||
|
import { task, traceAsync } from './lib/trace-runner';
|
||||||
|
import { createRuleset } from './lib/create-file';
|
||||||
|
import { fetchRemoteTextAndReadByLine } from './lib/fetch-text-by-line';
|
||||||
|
import { createTrie } from './lib/trie';
|
||||||
|
import { SHARED_DESCRIPTION } from './lib/constants';
|
||||||
|
import { createMemoizedPromise } from './lib/memo-promise';
|
||||||
|
|
||||||
|
const WHITELIST = [
|
||||||
|
'DOMAIN-SUFFIX,download.prss.microsoft.com',
|
||||||
|
'DOMAIN,res.cdn.office.net'
|
||||||
|
];
|
||||||
|
|
||||||
|
const BLACKLIST = [
|
||||||
|
'www.microsoft.com',
|
||||||
|
'learn.microsoft.com',
|
||||||
|
'devblogs.microsoft.com',
|
||||||
|
'docs.microsoft.com',
|
||||||
|
'developer.microsoft.com'
|
||||||
|
];
|
||||||
|
|
||||||
|
export const getMicrosoftCdnRulesetPromise = createMemoizedPromise(async () => {
|
||||||
|
const set = await traceAsync('fetch accelerated-domains.china.conf', async () => {
|
||||||
|
const trie = createTrie();
|
||||||
|
for await (const line of await fetchRemoteTextAndReadByLine('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/accelerated-domains.china.conf')) {
|
||||||
|
if (line.startsWith('server=/') && line.endsWith('/114.114.114.114')) {
|
||||||
|
const domain = line.slice(8, -16);
|
||||||
|
trie.add(domain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new Set(['.microsoft.com', '.windows.net', '.windows.com', '.windowsupdate.com', '.windowssearch.com', '.office.net'].flatMap(domain => trie.find(domain, false)));
|
||||||
|
});
|
||||||
|
|
||||||
|
const trie2 = createTrie(set);
|
||||||
|
BLACKLIST.flatMap(domain => trie2.find(domain, true)).forEach(d => set.delete(d));
|
||||||
|
|
||||||
|
return Array.from(set).map(d => `DOMAIN-SUFFIX,${d}`).concat(WHITELIST);
|
||||||
|
});
|
||||||
|
|
||||||
|
export const buildMicrosoftCdn = task(import.meta.path, async () => {
|
||||||
|
const description = [
|
||||||
|
...SHARED_DESCRIPTION,
|
||||||
|
'',
|
||||||
|
'This file contains Microsoft\'s domains using their China mainland CDN servers.',
|
||||||
|
'',
|
||||||
|
'Data from:',
|
||||||
|
' - https://github.com/felixonmars/dnsmasq-china-list'
|
||||||
|
];
|
||||||
|
|
||||||
|
return Promise.all(createRuleset(
|
||||||
|
'Sukka\'s Ruleset - Microsoft CDN',
|
||||||
|
description,
|
||||||
|
new Date(),
|
||||||
|
await getMicrosoftCdnRulesetPromise(),
|
||||||
|
'ruleset',
|
||||||
|
path.resolve(import.meta.dir, '../List/non_ip/microsoft_cdn.conf'),
|
||||||
|
path.resolve(import.meta.dir, '../Clash/non_ip/microsoft_cdn.txt')
|
||||||
|
));
|
||||||
|
});
|
||||||
|
|
||||||
|
if (import.meta.main) {
|
||||||
|
buildMicrosoftCdn();
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ import { ALL as AllStreamServices } from '../Source/stream';
|
|||||||
import { getChnCidrPromise } from './build-chn-cidr';
|
import { getChnCidrPromise } from './build-chn-cidr';
|
||||||
import { getTelegramCIDRPromise } from './build-telegram-cidr';
|
import { getTelegramCIDRPromise } from './build-telegram-cidr';
|
||||||
import { compareAndWriteFile } from './lib/create-file';
|
import { compareAndWriteFile } from './lib/create-file';
|
||||||
|
import { getMicrosoftCdnRulesetPromise } from './build-microsoft-cdn';
|
||||||
|
|
||||||
const POLICY_GROUPS: Array<[name: string, insertProxy: boolean, insertDirect: boolean]> = [
|
const POLICY_GROUPS: Array<[name: string, insertProxy: boolean, insertDirect: boolean]> = [
|
||||||
['Default Proxy', true, false],
|
['Default Proxy', true, false],
|
||||||
@@ -47,7 +48,7 @@ export const buildSSPanelUIMAppProfile = task(import.meta.path, async () => {
|
|||||||
// domestic - domains
|
// domestic - domains
|
||||||
getDomesticDomainsRulesetPromise().then(surgeRulesetToClashClassicalTextRuleset),
|
getDomesticDomainsRulesetPromise().then(surgeRulesetToClashClassicalTextRuleset),
|
||||||
getAppleCdnDomainsPromise().then(domains => domains.map(domain => `DOMAIN-SUFFIX,${domain}`)),
|
getAppleCdnDomainsPromise().then(domains => domains.map(domain => `DOMAIN-SUFFIX,${domain}`)),
|
||||||
processLineFromReadline(readFileByLine(path.resolve(import.meta.dir, '../Source/non_ip/microsoft_cdn.conf'))),
|
getMicrosoftCdnRulesetPromise().then(surgeRulesetToClashClassicalTextRuleset),
|
||||||
processLineFromReadline(readFileByLine(path.resolve(import.meta.dir, '../Source/non_ip/apple_cn.conf'))),
|
processLineFromReadline(readFileByLine(path.resolve(import.meta.dir, '../Source/non_ip/apple_cn.conf'))),
|
||||||
processLineFromReadline(readFileByLine(path.resolve(import.meta.dir, '../Source/non_ip/neteasemusic.conf'))).then(surgeRulesetToClashClassicalTextRuleset),
|
processLineFromReadline(readFileByLine(path.resolve(import.meta.dir, '../Source/non_ip/neteasemusic.conf'))).then(surgeRulesetToClashClassicalTextRuleset),
|
||||||
// microsoft & apple - domains
|
// microsoft & apple - domains
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { toASCII } from 'punycode';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { traceAsync } from './trace-runner';
|
import { traceAsync } from './trace-runner';
|
||||||
import { defaultRequestInit, fetchWithRetry } from './fetch-retry';
|
import { defaultRequestInit, fetchWithRetry } from './fetch-retry';
|
||||||
import type { PublicSuffixList } from '@gorhill/publicsuffixlist';
|
import { createMemoizedPromise } from './memo-promise';
|
||||||
|
|
||||||
const publicSuffixPath = path.resolve(import.meta.dir, '../../node_modules/.cache/public_suffix_list_dat.txt');
|
const publicSuffixPath = path.resolve(import.meta.dir, '../../node_modules/.cache/public_suffix_list_dat.txt');
|
||||||
|
|
||||||
@@ -27,8 +27,4 @@ const getGorhillPublicSuffix = () => traceAsync('create gorhill public suffix in
|
|||||||
return gorhill;
|
return gorhill;
|
||||||
});
|
});
|
||||||
|
|
||||||
let gorhillPublicSuffixPromise: Promise<PublicSuffixList> | null = null;
|
export const getGorhillPublicSuffixPromise = createMemoizedPromise(getGorhillPublicSuffix);
|
||||||
export const getGorhillPublicSuffixPromise = () => {
|
|
||||||
gorhillPublicSuffixPromise ||= getGorhillPublicSuffix();
|
|
||||||
return gorhillPublicSuffixPromise;
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -384,8 +384,9 @@ rules:
|
|||||||
|
|
||||||
#### Microsoft CDN
|
#### Microsoft CDN
|
||||||
|
|
||||||
- 人工维护
|
- 自动生成
|
||||||
- 规则组包含 Microsoft 在中华人民共和国完成工信部 ICP 备案和公安网备、且在中华人民共和国境内提供 HTTP 服务的域名,如果由于某些原因需要代理其中部分域名,请自行针对域名编写规则、并添加到当前规则组之前。
|
- 规则组包含 Microsoft 在中华人民共和国完成工信部 ICP 备案和公安网备、且在中华人民共和国境内提供 HTTP 服务的域名,如果由于某些原因需要代理其中部分域名,请自行针对域名编写规则、并添加到当前规则组之前。
|
||||||
|
- 数据来源 [`felixonmars/dnsmasq-china-list`](https://github.com/felixonmars/dnsmasq-china-list/blob/master/apple.china.conf)
|
||||||
|
|
||||||
**Surge**
|
**Surge**
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
# $ meta_title Sukka's Ruleset - Microsoft Domains
|
|
||||||
# $ meta_description This file contains domains of Microsoft that have PoP inside the Mainland China.
|
|
||||||
|
|
||||||
DOMAIN-SUFFIX,dl.delivery.mp.microsoft.com
|
|
||||||
DOMAIN-SUFFIX,download.windowsupdate.com
|
|
||||||
DOMAIN-SUFFIX,download.prss.microsoft.com
|
|
||||||
DOMAIN,res.cdn.office.net
|
|
||||||
DOMAIN,build.microsoft.com
|
|
||||||
DOMAIN,cn.windowssearch.com
|
|
||||||
DOMAIN,ctldl.windowsupdate.com
|
|
||||||
DOMAIN,download.microsoft.com
|
|
||||||
DOMAIN,download.visualstudio.microsoft.com
|
|
||||||
DOMAIN,fs.microsoft.com
|
|
||||||
DOMAIN,officecdn.microsoft.com
|
|
||||||
DOMAIN,sdx.microsoft.com
|
|
||||||
DOMAIN,storeedgefd.dsx.mp.microsoft.com
|
|
||||||
DOMAIN,wscont1.apps.microsoft.com
|
|
||||||
DOMAIN,wscont2.apps.microsoft.com
|
|
||||||
Reference in New Issue
Block a user