mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Refactor: simplify build infra
This commit is contained in:
@@ -7,8 +7,9 @@ import { processLine } from './lib/process-line';
|
||||
import { createRuleset } from './lib/create-file';
|
||||
import { task } from './lib/trace-runner';
|
||||
import { SHARED_DESCRIPTION } from './lib/constants';
|
||||
import { createMemoizedPromise } from './lib/memo-promise';
|
||||
|
||||
export const buildTelegramCIDR = task(import.meta.path, async () => {
|
||||
export const getTelegramCIDRPromise = createMemoizedPromise(async () => {
|
||||
const resp = await fetchWithRetry('https://core.telegram.org/resources/cidr.txt', defaultRequestInit) as Response;
|
||||
const lastModified = resp.headers.get('last-modified');
|
||||
const date = lastModified ? new Date(lastModified) : new Date();
|
||||
@@ -28,6 +29,12 @@ export const buildTelegramCIDR = task(import.meta.path, async () => {
|
||||
}
|
||||
}
|
||||
|
||||
return { date, results };
|
||||
});
|
||||
|
||||
export const buildTelegramCIDR = task(import.meta.path, async () => {
|
||||
const { date, results } = await getTelegramCIDRPromise();
|
||||
|
||||
if (results.length === 0) {
|
||||
throw new Error('Failed to fetch data!');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user