mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Update Microsoft CDN
This commit is contained in:
@@ -5,13 +5,16 @@ import { SHARED_DESCRIPTION } from './lib/constants';
|
||||
import { createMemoizedPromise } from './lib/memo-promise';
|
||||
import { extractDomainsFromFelixDnsmasq } from './lib/parse-dnsmasq';
|
||||
import { RulesetOutput } from './lib/create-file';
|
||||
import { appendArrayInPlace } from './lib/append-array-in-place';
|
||||
|
||||
const PROBE_DOMAINS = ['.microsoft.com', '.windows.net', '.windows.com', '.windowsupdate.com', '.windowssearch.com', '.office.net'];
|
||||
|
||||
const WHITELIST = [
|
||||
'DOMAIN-SUFFIX,download.prss.microsoft.com',
|
||||
'DOMAIN,res.cdn.office.net'
|
||||
const DOMAINS = [
|
||||
'res.cdn.office.net',
|
||||
'res-1.cdn.office.net',
|
||||
'statics.teams.cdn.office.net'
|
||||
];
|
||||
const DOMAIN_SUFFIXES = ['download.prss.microsoft.com'];
|
||||
|
||||
const BLACKLIST = [
|
||||
'www.microsoft.com',
|
||||
@@ -22,7 +25,7 @@ const BLACKLIST = [
|
||||
'windowsupdate.com'
|
||||
];
|
||||
|
||||
export const getMicrosoftCdnRulesetPromise = createMemoizedPromise(async () => {
|
||||
export const getMicrosoftCdnRulesetPromise = createMemoizedPromise<[domains: string[], domainSuffixes: string[]]>(async () => {
|
||||
// First trie is to find the microsoft domains that matches probe domains
|
||||
const trie = createTrie(null, false);
|
||||
for await (const line of await fetchRemoteTextByLine('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/accelerated-domains.china.conf')) {
|
||||
@@ -37,9 +40,12 @@ export const getMicrosoftCdnRulesetPromise = createMemoizedPromise(async () => {
|
||||
const trie2 = createTrie(foundMicrosoftCdnDomains, true);
|
||||
BLACKLIST.forEach(trie2.whitelist);
|
||||
|
||||
return trie2.dump()
|
||||
.map(d => `DOMAIN-SUFFIX,${d}`)
|
||||
.concat(WHITELIST);
|
||||
const domains: string[] = DOMAINS;
|
||||
const domainSuffixes: string[] = DOMAIN_SUFFIXES;
|
||||
|
||||
appendArrayInPlace(domainSuffixes, trie2.dump());
|
||||
|
||||
return [domains, domainSuffixes] as const;
|
||||
});
|
||||
|
||||
export const buildMicrosoftCdn = task(require.main === module, __filename)(async (span) => {
|
||||
@@ -52,11 +58,12 @@ export const buildMicrosoftCdn = task(require.main === module, __filename)(async
|
||||
' - https://github.com/felixonmars/dnsmasq-china-list'
|
||||
];
|
||||
|
||||
const res: string[] = await span.traceChildPromise('get microsoft cdn domains', getMicrosoftCdnRulesetPromise());
|
||||
const [domains, domainSuffixes] = await span.traceChildPromise('get microsoft cdn domains', getMicrosoftCdnRulesetPromise());
|
||||
|
||||
return new RulesetOutput(span, 'microsoft_cdn', 'non_ip')
|
||||
.withTitle('Sukka\'s Ruleset - Microsoft CDN')
|
||||
.withDescription(description)
|
||||
.addFromRuleset(res)
|
||||
.bulkAddDomain(domains)
|
||||
.bulkAddDomainSuffix(domainSuffixes)
|
||||
.write();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user