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