Minor changes to previous build downloading

This commit is contained in:
SukkaW 2024-02-20 13:36:08 +08:00
parent 73f6d4bc6b
commit 59b2608ef2
5 changed files with 12 additions and 14 deletions

View File

@ -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'));

View File

@ -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) {

View File

@ -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));
}
});
});

View File

@ -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',

View File

@ -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));