mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 01:00:34 +08:00
Minor changes to previous build downloading
This commit is contained in:
parent
73f6d4bc6b
commit
59b2608ef2
@ -4,7 +4,7 @@ import { readFileIntoProcessedArray } from './lib/fetch-text-by-line';
|
||||
import { createTrie } from './lib/trie';
|
||||
import { task } from './trace';
|
||||
import { SHARED_DESCRIPTION } from './lib/constants';
|
||||
import { getPublicSuffixListTextPromise } from './download-publicsuffixlist';
|
||||
import { getPublicSuffixListTextPromise } from './lib/download-publicsuffixlist';
|
||||
|
||||
const getS3OSSDomainsPromise = (async (): Promise<Set<string>> => {
|
||||
const trie = createTrie((await getPublicSuffixListTextPromise()).split('\n'));
|
||||
|
||||
@ -22,8 +22,8 @@ const s = new Sema(2);
|
||||
const latestTopUserAgentsPromise = fsFetchCache.apply(
|
||||
'https://unpkg.com/top-user-agents@latest/src/desktop.json',
|
||||
() => fetchWithRetry('https://unpkg.com/top-user-agents@latest/src/desktop.json')
|
||||
.then(res => res.json<string[]>())
|
||||
.then(userAgents => userAgents.filter(ua => ua.startsWith('Mozilla/5.0 '))),
|
||||
.then(res => res.json())
|
||||
.then((userAgents: string[]) => userAgents.filter(ua => ua.startsWith('Mozilla/5.0 '))),
|
||||
{
|
||||
serializer: serializeArray,
|
||||
deserializer: deserializeArray,
|
||||
@ -62,7 +62,7 @@ const querySpeedtestApi = async (keyword: string): Promise<Array<string | null>>
|
||||
retry: {
|
||||
retries: 2
|
||||
}
|
||||
})).then(r => r.json<Array<{ url: string }>>()).then(data => data.reduce<string[]>(
|
||||
})).then(r => r.json()).then((data: Array<{ url: string }>) => data.reduce<string[]>(
|
||||
(prev, cur) => {
|
||||
const hn = tldts.getHostname(cur.url, { detectIp: false });
|
||||
if (hn) {
|
||||
|
||||
@ -61,10 +61,11 @@ export const downloadPreviousBuild = task(import.meta.path, async (span) => {
|
||||
throw new Error('Download previous build failed! No body found');
|
||||
}
|
||||
|
||||
const extract = tarStream.extract();
|
||||
const gunzip = zlib.createGunzip();
|
||||
const extract = tarStream.extract();
|
||||
|
||||
pipeline(
|
||||
Readable.fromWeb(resp.body) as any,
|
||||
Readable.fromWeb(resp.body as unknown as import('stream/web').ReadableStream<any>),
|
||||
gunzip,
|
||||
extract
|
||||
);
|
||||
@ -86,10 +87,7 @@ export const downloadPreviousBuild = task(import.meta.path, async (span) => {
|
||||
const targetPath = path.join(import.meta.dir, '..', relativeEntryPath);
|
||||
|
||||
await mkdir(path.dirname(targetPath), { recursive: true });
|
||||
await pipeline(
|
||||
entry as any,
|
||||
createWriteStream(targetPath)
|
||||
);
|
||||
await pipeline(entry, createWriteStream(targetPath));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { TTL, fsFetchCache } from './lib/cache-filesystem';
|
||||
import { defaultRequestInit, fetchWithRetry } from './lib/fetch-retry';
|
||||
import { createMemoizedPromise } from './lib/memo-promise';
|
||||
import { TTL, fsFetchCache } from './cache-filesystem';
|
||||
import { defaultRequestInit, fetchWithRetry } from './fetch-retry';
|
||||
import { createMemoizedPromise } from './memo-promise';
|
||||
|
||||
export const getPublicSuffixListTextPromise = createMemoizedPromise(() => fsFetchCache.apply(
|
||||
'https://publicsuffix.org/list/public_suffix_list.dat',
|
||||
@ -1,6 +1,6 @@
|
||||
import { toASCII } from 'punycode';
|
||||
import { createMemoizedPromise } from './memo-promise';
|
||||
import { getPublicSuffixListTextPromise } from '../download-publicsuffixlist';
|
||||
import { getPublicSuffixListTextPromise } from './download-publicsuffixlist';
|
||||
|
||||
const customFetch = (url: string | URL): Promise<Blob> => Promise.resolve(Bun.file(url));
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user