Update CDN Hosts

This commit is contained in:
SukkaW 2022-12-09 21:55:34 +08:00
parent aedcddff9f
commit 16bbc886d1
4 changed files with 50 additions and 26 deletions

View File

@ -8,6 +8,12 @@ const { Stream, Readable } = require('stream');
const { promisify } = require('util');
const pipeline = promisify(Stream.pipeline);
const fileExists = (path) => {
return fs.promises.access(path, fs.constants.F_OK)
.then(() => true)
.catch(() => false);
};
(async () => {
const filesList = (
await fs.promises.readFile(resolve(__dirname, '../.gitignore'), { encoding: 'utf-8' })
@ -15,32 +21,40 @@ const pipeline = promisify(Stream.pipeline);
.split('\n')
.filter(p => p.startsWith('List/'));
const tempFile = join(tmpdir(), `sukka-surge-last-build-tar-${Date.now()}`);
const resp = await fetch('https://codeload.github.com/sukkaw/surge/tar.gz/gh-pages');
const readableNodeStream = Readable.fromWeb(resp.body);
await pipeline(
readableNodeStream,
fs.createWriteStream(tempFile)
);
if (
(await Promise.all(
filesList.map(p => fileExists(join(__dirname, '..', p)))
)).some(exist => !exist)
) {
const tempFile = join(tmpdir(), `sukka-surge-last-build-tar-${Date.now()}`);
const resp = await fetch('https://codeload.github.com/sukkaw/surge/tar.gz/gh-pages');
const readableNodeStream = Readable.fromWeb(resp.body);
await pipeline(
readableNodeStream,
fs.createWriteStream(tempFile)
);
const extractedPath = join(tmpdir(), `sukka-surge-last-build-extracted-${Date.now()}`);
await fse.ensureDir(extractedPath);
await tar.x({
file: tempFile,
cwd: extractedPath,
filter: (p) => {
return p.split('/')[1] === 'List'
}
});
const extractedPath = join(tmpdir(), `sukka-surge-last-build-extracted-${Date.now()}`);
await fse.ensureDir(extractedPath);
await tar.x({
file: tempFile,
cwd: extractedPath,
filter: (p) => {
return p.split('/')[1] === 'List'
}
});
await Promise.all(filesList.map(p => fse.copy(
join(extractedPath, 'Surge-gh-pages', p),
join(__dirname, '..', p),
{
overwrite: true
}
)))
await Promise.all(filesList.map(p => fse.copy(
join(extractedPath, 'Surge-gh-pages', p),
join(__dirname, '..', p),
{
overwrite: true
}
)))
await fs.promises.unlink(tempFile).catch(() => {});
await fs.promises.unlink(extractedPath).catch(() => {});
await fs.promises.unlink(tempFile).catch(() => { });
await fs.promises.unlink(extractedPath).catch(() => { });
} else {
console.log('All files exists, skip download.');
}
})();

View File

@ -878,6 +878,10 @@ static-cdn.mastodon.social
.wsimg.com
# SurveyMonkey
.smassets.net
# Envato
.envato-static.com
.envatousercontent.com
s3.envato.com
# Others
.yelpcdn.com
cf-images.us-east-1.prod.boltdns.net

View File

@ -2,6 +2,9 @@
.nitro.download
.download.mokeedev.com
get.pixelexperience.org
download.pixelexperience.org
# >> MEGA
.mega.nz

View File

@ -52,7 +52,10 @@
]
},
"build:telegram-cidr": {
"command": "node ./Build/build-telegram-cidr.js"
"command": "node ./Build/build-telegram-cidr.js",
"dependencies": [
"download-previous-build"
]
},
"build:chn-cidr": {
"command": "node ./Build/build-chn-cidr.js",