mirror of
https://github.com/SukkaW/Surge.git
synced 2026-02-03 20:41:52 +08:00
New build infra
This commit is contained in:
@@ -2,12 +2,16 @@ const { fetchWithRetry } = require('./lib/fetch-retry');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { isIPv4, isIPv6 } = require('net');
|
||||
const { compareAndWriteFile } = require('./lib/string-array-compare');
|
||||
const { withBannerArray } = require('./lib/with-banner');
|
||||
|
||||
(async () => {
|
||||
console.time('Total Time - build-telegram-cidr');
|
||||
|
||||
/** @type {Response} */
|
||||
const resp = await fetchWithRetry('https://core.telegram.org/resources/cidr.txt');
|
||||
const lastModified = new Date(resp.headers.get('last-modified'));
|
||||
const lastModified = resp.headers.get('last-modified');
|
||||
const date = lastModified ? new Date(lastModified) : new Date();
|
||||
|
||||
const res = (await resp.text())
|
||||
.split('\n')
|
||||
@@ -17,23 +21,31 @@ const { isIPv4, isIPv6 } = require('net');
|
||||
throw new Error('Failed to fetch data!');
|
||||
}
|
||||
|
||||
await fs.promises.writeFile(
|
||||
path.resolve(__dirname, '../List/ip/telegram.conf'),
|
||||
'# Telegram CIDR (https://core.telegram.org/resources/cidr.txt)' + '\n' +
|
||||
'# Last Updated: ' + lastModified.toISOString() + '\n' +
|
||||
res.map(ip => {
|
||||
const [subnet] = ip.split('/');
|
||||
console.log(' - ' + ip + ': ' + subnet);
|
||||
if (isIPv4(subnet)) {
|
||||
return `IP-CIDR,${ip},no-resolve`;
|
||||
}
|
||||
if (isIPv6(subnet)) {
|
||||
return `IP-CIDR6,${ip},no-resolve`;
|
||||
}
|
||||
return '';
|
||||
}).join('\n') + '\n',
|
||||
'utf-8'
|
||||
);
|
||||
await compareAndWriteFile(
|
||||
withBannerArray(
|
||||
'Sukka\'s Surge Rules - Telegram IP CIDR',
|
||||
[
|
||||
'License: AGPL 3.0',
|
||||
'Homepage: https://ruleset.skk.moe',
|
||||
'GitHub: https://github.com/SukkaW/Surge',
|
||||
'Data from:',
|
||||
' - https://core.telegram.org/resources/cidr.txt'
|
||||
],
|
||||
date,
|
||||
res.map(ip => {
|
||||
const [subnet] = ip.split('/');
|
||||
console.log(' - ' + ip + ': ' + subnet);
|
||||
if (isIPv4(subnet)) {
|
||||
return `IP-CIDR,${ip},no-resolve`;
|
||||
}
|
||||
if (isIPv6(subnet)) {
|
||||
return `IP-CIDR6,${ip},no-resolve`;
|
||||
}
|
||||
return '';
|
||||
})
|
||||
),
|
||||
path.resolve(__dirname, '../List/ip/telegram.conf')
|
||||
)
|
||||
|
||||
console.timeEnd('Total Time - build-telegram-cidr');
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user