mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-28 17:41:54 +08:00
Feat: introduce make-fetch-happen (#44)
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
import path from 'node:path';
|
||||
import fs from 'node:fs';
|
||||
import { pipeline } from 'node:stream/promises';
|
||||
import picocolors from 'picocolors';
|
||||
import { task } from './trace';
|
||||
import { defaultRequestInit, fetchWithRetry } from './lib/fetch-retry';
|
||||
import { extract as tarExtract } from 'tar-fs';
|
||||
import type { Headers as TarEntryHeaders } from 'tar-fs';
|
||||
import zlib from 'node:zlib';
|
||||
import { Readable } from 'node:stream';
|
||||
import picocolors from 'picocolors';
|
||||
import { $fetch } from './lib/make-fetch-happen';
|
||||
|
||||
const GITHUB_CODELOAD_URL = 'https://codeload.github.com/sukkalab/ruleset.skk.moe/tar.gz/master';
|
||||
const GITLAB_CODELOAD_URL = 'https://gitlab.com/SukkaW/ruleset.skk.moe/-/archive/master/ruleset.skk.moe-master.tar.gz';
|
||||
@@ -21,13 +20,7 @@ export const downloadPreviousBuild = task(require.main === module, __filename)(a
|
||||
}
|
||||
|
||||
const tarGzUrl = await span.traceChildAsync('get tar.gz url', async () => {
|
||||
const resp = await fetchWithRetry(GITHUB_CODELOAD_URL, {
|
||||
...defaultRequestInit,
|
||||
method: 'HEAD',
|
||||
retry: {
|
||||
retryOnNon2xx: false
|
||||
}
|
||||
});
|
||||
const resp = await $fetch(GITHUB_CODELOAD_URL, { method: 'HEAD' });
|
||||
if (resp.status !== 200) {
|
||||
console.warn('Download previous build from GitHub failed! Status:', resp.status);
|
||||
console.warn('Switch to GitLab');
|
||||
@@ -37,19 +30,12 @@ export const downloadPreviousBuild = task(require.main === module, __filename)(a
|
||||
});
|
||||
|
||||
return span.traceChildAsync('download & extract previoud build', async () => {
|
||||
const resp = await fetchWithRetry(tarGzUrl, {
|
||||
const resp = await $fetch(tarGzUrl, {
|
||||
headers: {
|
||||
'User-Agent': 'curl/8.9.1',
|
||||
// https://github.com/unjs/giget/issues/97
|
||||
// https://gitlab.com/gitlab-org/gitlab/-/commit/50c11f278d18fe1f3fb12eb595067216bb58ade2
|
||||
'sec-fetch-mode': 'same-origin'
|
||||
},
|
||||
// https://github.com/unjs/giget/issues/97
|
||||
// https://gitlab.com/gitlab-org/gitlab/-/commit/50c11f278d18fe1f3fb12eb595067216bb58ade2
|
||||
|
||||
mode: 'same-origin',
|
||||
retry: {
|
||||
retryOnNon2xx: false
|
||||
}
|
||||
});
|
||||
|
||||
@@ -79,7 +65,7 @@ export const downloadPreviousBuild = task(require.main === module, __filename)(a
|
||||
);
|
||||
|
||||
return pipeline(
|
||||
Readable.fromWeb(resp.body),
|
||||
resp.body,
|
||||
gunzip,
|
||||
extract
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user