Output hostname size of sgmodule build

This commit is contained in:
SukkaW 2024-10-21 01:01:48 +08:00
parent 8e2644ac6c
commit 94ea47d447
3 changed files with 11 additions and 16 deletions

View File

@ -31,8 +31,6 @@ const REDIRECT_MIRROR_HEADER = [
['gapis.geekzu.org/g-fonts/', 'https://fonts.gstatic.com/'],
['gapis.geekzu.org/g-themes/', 'https://themes.googleusercontent.com/'],
['sdn.geekzu.org/', 'https://secure.gravatar.com/'],
// cravatar
['cravatar.cn/', 'https://secure.gravatar.com/'],
// libravatar
['seccdn.libravatar.org/gravatarproxy/', 'https://secure.gravatar.com/'],
// ghproxy
@ -53,16 +51,14 @@ const REDIRECT_MIRROR_HEADER = [
['cdn.gitmirror.com/', 'https://cdn.statically.io/'],
// FastGit
['raw.fastgit.org/', 'https://raw.githubusercontent.com/'],
['assets.fastgit.org/', 'https://github.githubassets.com/'],
// ['assets.fastgit.org/', 'https://github.githubassets.com/'],
// jsDelivr
['fastly.jsdelivr.net/', 'https://cdn.jsdelivr.net/'],
['gcore.jsdelivr.net/', 'https://cdn.jsdelivr.net/'],
['testingcf.jsdelivr.net/', 'https://cdn.jsdelivr.net/'],
// JSDMirror
['cdn.jsdmirror.com/', 'https://cdn.jsdelivr.net/'],
['cdn.jsdmirror.cn/', 'https://cdn.jsdelivr.net/'],
// ops.ci
['jsdelivr.ops.ci/', 'https://cdn.jsdelivr.net/'],
['fonts.ops.ci/', 'https://fonts.googleapis.com/'],
// onmicrosoft.cn
['jsd.onmicrosoft.cn/', 'https://cdn.jsdelivr.net/'],
['npm.onmicrosoft.cn/', 'https://unpkg.com/'],
@ -79,9 +75,7 @@ const REDIRECT_MIRROR_HEADER = [
['fastly-polyfill.net/', 'https://cdnjs.cloudflare.com/polyfill/'],
// BootCDN has been controlled by a malicious actor and being used to spread malware
['cdn.bootcss.com/', 'https://cdnjs.cloudflare.com/ajax/libs/'],
['cdn.bootcdn.net/', 'https://cdnjs.cloudflare.com/ajax/libs/'],
['cdn.bootcdn.com/', 'https://cdnjs.cloudflare.com/ajax/libs/'],
['cdn.staticfile.net/', 'https://cdnjs.cloudflare.com/ajax/libs/'],
['cdn.staticfile.org/', 'https://cdnjs.cloudflare.com/ajax/libs/'],
// Misc
@ -148,7 +142,7 @@ const REDIRECT_FAKEWEBSITES = [
export const buildRedirectModule = task(require.main === module, __filename)(async (span) => {
const domains = Array.from(new Set([
...REDIRECT_MIRROR_HEADER.map(([from]) => getHostname(from, { detectIp: false })),
...REDIRECT_FAKEWEBSITES.flatMap(([from]) => [from, `www.${from}`]),
...REDIRECT_FAKEWEBSITES.flatMap(([from]) => [from, `*.${from}`]),
...REDIRECT_MIRROR_307.map(([from]) => getHostname(from, { detectIp: false }))
])).filter(isTruthy);
@ -156,7 +150,7 @@ export const buildRedirectModule = task(require.main === module, __filename)(asy
span,
[
'#!name=[Sukka] URL Redirect',
`#!desc=Last Updated: ${new Date().toISOString()}`,
`#!desc=Last Updated: ${new Date().toISOString()} Size: ${domains.length}`,
'',
'[MITM]',
`hostname = %APPEND% ${domains.join(', ')}`,

View File

@ -115,7 +115,6 @@ export abstract class RuleOutput<TPreprocessed = unknown> {
}
private async addFromDomainsetPromise(source: AsyncIterable<string> | Iterable<string> | string[]) {
// eslint-disable-next-line @typescript-eslint/await-thenable -- https://github.com/typescript-eslint/typescript-eslint/issues/10080
for await (const line of source) {
if (line[0] === '.') {
this.addDomainSuffix(line);
@ -131,7 +130,6 @@ export abstract class RuleOutput<TPreprocessed = unknown> {
}
private async addFromRulesetPromise(source: AsyncIterable<string> | Iterable<string>) {
// eslint-disable-next-line @typescript-eslint/await-thenable -- https://github.com/typescript-eslint/typescript-eslint/issues/10080
for await (const line of source) {
const splitted = line.split(',');
const type = splitted[0];
@ -303,13 +301,14 @@ export abstract class RuleOutput<TPreprocessed = unknown> {
if (this.mitmSgmodule) {
const sgmodule = this.mitmSgmodule();
const sgMOdulePath = this.mitmSgmodulePath ?? path.join(this.type, this.id + '.sgmodule');
const sgModulePath = this.mitmSgmodulePath ?? path.join(this.type, this.id + '.sgmodule');
if (sgmodule) {
promises.push(
compareAndWriteFile(
this.span,
sgmodule,
path.join(OUTPUT_MODULES_DIR, sgMOdulePath)
path.join(OUTPUT_MODULES_DIR, sgModulePath)
)
);
}

View File

@ -262,12 +262,14 @@ export class RulesetOutput extends RuleOutput<Preprocessed> {
console.table(parsedFailures);
}
const hostnames = Array.from(new Set(parsed.map(i => i[1])));
return [
'#!name=[Sukka] Surge Reject MITM',
'#!desc=为 URL Regex 规则组启用 MITM',
`#!desc=为 URL Regex 规则组启用 MITM (size: ${hostnames.length})`,
'',
'[MITM]',
'hostname = %APPEND% ' + Array.from(new Set(parsed.map(i => i[1]))).join(', ')
'hostname = %APPEND% ' + hostnames.join(', ')
];
}
}