-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
64 additions
and
46 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
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'; | ||
|
||
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 buildMicrosoftCdn = task(import.meta.path, 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)); | ||
|
||
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' | ||
]; | ||
|
||
const ruleset = Array.from(set).map(d => `DOMAIN-SUFFIX,${d}`).concat(WHITELIST); | ||
|
||
return Promise.all(createRuleset( | ||
'Sukka\'s Ruleset - Microsoft CDN', | ||
description, | ||
new Date(), | ||
ruleset, | ||
'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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.