mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Chore: housekeeping
This commit is contained in:
@@ -14,7 +14,7 @@ const getBogusNxDomainIPsPromise = fsFetchCache.apply(
|
||||
async () => {
|
||||
const result: string[] = [];
|
||||
for await (const line of await fetchRemoteTextByLine(URL)) {
|
||||
if (line && line.startsWith('bogus-nxdomain=')) {
|
||||
if (line.startsWith('bogus-nxdomain=')) {
|
||||
const ip = line.slice(15).trim();
|
||||
if (isProbablyIpv4(ip)) {
|
||||
result.push(`IP-CIDR,${ip}/32,no-resolve`);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// eslint-disable-next-line import/no-unresolved -- bun
|
||||
// eslint-disable-next-line import-x/no-unresolved -- bun
|
||||
import { describe, expect, it } from 'bun:test';
|
||||
import createKeywordFilter from './aho-corasick';
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// eslint-disable-next-line import/no-unresolved -- bun built-in module
|
||||
// eslint-disable-next-line import-x/no-unresolved -- bun built-in module
|
||||
import { Database } from 'bun:sqlite';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
|
||||
@@ -8,11 +8,11 @@ class CustomAbortError extends Error {
|
||||
|
||||
const sleepWithAbort = (ms: number, signal: AbortSignal) => new Promise<void>((resolve, reject) => {
|
||||
if (signal.aborted) {
|
||||
reject(signal.reason);
|
||||
reject(signal.reason as Error);
|
||||
return;
|
||||
}
|
||||
|
||||
function stop(this: AbortSignal) { reject(this.reason); }
|
||||
function stop(this: AbortSignal) { reject(this.reason as Error); }
|
||||
|
||||
signal.addEventListener('abort', stop, { once: true });
|
||||
Bun.sleep(ms).then(resolve).catch(reject).finally(() => signal.removeEventListener('abort', stop));
|
||||
|
||||
@@ -7,12 +7,13 @@ const MAX_RETRIES = 5;
|
||||
const MAX_RETRY_AFTER = 20;
|
||||
const FACTOR = 6;
|
||||
|
||||
function isClientError(err: any): err is NodeJS.ErrnoException {
|
||||
if (!err) return false;
|
||||
return (
|
||||
err.code === 'ERR_UNESCAPED_CHARACTERS'
|
||||
|| err.message === 'Request path contains unescaped characters'
|
||||
);
|
||||
function isClientError(err: unknown): err is NodeJS.ErrnoException {
|
||||
if (!err || typeof err !== 'object') return false;
|
||||
|
||||
if ('code' in err) return err.code === 'ERR_UNESCAPED_CHARACTERS';
|
||||
if ('message' in err) return err.message === 'Request path contains unescaped characters';
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export class ResponseError extends Error {
|
||||
@@ -70,7 +71,7 @@ function createFetchRetry($fetch: typeof fetch): FetchWithRetry {
|
||||
return await retry<Response>(async (bail) => {
|
||||
try {
|
||||
// this will be retried
|
||||
const res = (await $fetch(url, opts)) as Response;
|
||||
const res = (await $fetch(url, opts));
|
||||
|
||||
if ((res.status >= 500 && res.status < 600) || res.status === 429) {
|
||||
// NOTE: doesn't support http-date format
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createTrie } from './trie';
|
||||
// eslint-disable-next-line import/no-unresolved -- fuck eslint-import
|
||||
// eslint-disable-next-line import-x/no-unresolved -- fuck eslint-import
|
||||
import { describe, expect, it } from 'bun:test';
|
||||
|
||||
describe('Trie', () => {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { fetchRemoteTextByLine, readFileByLine } from './lib/fetch-text-by-line';
|
||||
import { Readable } from 'stream';
|
||||
import { parse } from 'csv-parse/sync';
|
||||
import { createTrie } from './lib/trie';
|
||||
import path from 'path';
|
||||
|
||||
Reference in New Issue
Block a user