mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Chore: add fetch UA
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import type { BunFile } from 'bun';
|
||||
import { fetchWithRetry } from './fetch-retry';
|
||||
import { fetchWithRetry, defaultRequestInit } from './fetch-retry';
|
||||
|
||||
const decoder = new TextDecoder('utf-8');
|
||||
|
||||
@@ -56,6 +56,6 @@ export async function* createReadlineInterfaceFromResponse(resp: Response): Asyn
|
||||
}
|
||||
}
|
||||
|
||||
export function fetchRemoteTextAndCreateReadlineInterface(url: string | URL, opt?: RequestInit): Promise<AsyncGenerator<string>> {
|
||||
return fetchWithRetry(url, opt).then(res => createReadlineInterfaceFromResponse(res));
|
||||
export function fetchRemoteTextAndCreateReadlineInterface(url: string | URL): Promise<AsyncGenerator<string>> {
|
||||
return fetchWithRetry(url, defaultRequestInit).then(res => createReadlineInterfaceFromResponse(res));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
// @ts-expect-error -- missing types
|
||||
import createFetchRetry from '@vercel/fetch-retry';
|
||||
|
||||
export const defaultRequestInit: RequestInit = {
|
||||
headers: {
|
||||
'User-Agent': 'curl/8.1.2 (https://github.com/SukkaW/Surge)'
|
||||
}
|
||||
}
|
||||
|
||||
export const fetchWithRetry: typeof fetch = createFetchRetry(fetch);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { toASCII } from 'punycode';
|
||||
import path from 'path';
|
||||
import { traceAsync } from './trace-runner';
|
||||
import { defaultRequestInit, fetchWithRetry } from './fetch-retry';
|
||||
import type { PublicSuffixList } from 'gorhill-publicsuffixlist';
|
||||
|
||||
const publicSuffixPath = path.resolve(__dirname, '../../node_modules/.cache/public_suffix_list_dat.txt');
|
||||
@@ -13,7 +14,7 @@ const getGorhillPublicSuffix = () => traceAsync('create gorhill public suffix in
|
||||
const [publicSuffixListDat, { default: gorhill }] = await Promise.all([
|
||||
await publicSuffixFile.exists()
|
||||
? publicSuffixFile.text()
|
||||
: fetch('https://publicsuffix.org/list/public_suffix_list.dat').then(r => {
|
||||
: fetchWithRetry('https://publicsuffix.org/list/public_suffix_list.dat', defaultRequestInit).then(r => {
|
||||
console.log('public_suffix_list.dat not found, fetch directly from remote.');
|
||||
return r.text();
|
||||
}),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// @ts-check
|
||||
import { fetchWithRetry } from './fetch-retry';
|
||||
import { defaultRequestInit, fetchWithRetry } from './fetch-retry';
|
||||
import * as tldts from './cached-tld-parse';
|
||||
import { fetchRemoteTextAndCreateReadlineInterface } from './fetch-remote-text-by-line';
|
||||
import { NetworkFilter } from '@cliqz/adblocker';
|
||||
@@ -198,7 +198,7 @@ export async function processFilterRules(
|
||||
filterRules = (
|
||||
await Promise.any(
|
||||
[filterRulesUrl, ...(fallbackUrls || [])].map(async url => {
|
||||
const r = await fetchWithRetry(url, { signal: controller.signal });
|
||||
const r = await fetchWithRetry(url, { signal: controller.signal, ...defaultRequestInit });
|
||||
const text = await r.text();
|
||||
|
||||
controller.abort();
|
||||
|
||||
@@ -106,9 +106,10 @@ export const ADGUARD_FILTERS = [
|
||||
[
|
||||
'https://curbengh.github.io/urlhaus-filter/urlhaus-filter-agh-online.txt',
|
||||
[
|
||||
'https://urlhaus-filter.pages.dev/urlhaus-filter-agh-online.txt'
|
||||
'https://urlhaus-filter.pages.dev/urlhaus-filter-agh-online.txt',
|
||||
// Prefer mirror, since malware-filter.gitlab.io has not been updated for a while
|
||||
// 'https://malware-filter.gitlab.io/urlhaus-filter/urlhaus-filter-agh-online.txt'
|
||||
// 'https://malware-filter.gitlab.io/urlhaus-filter/urlhaus-filter-agh-online.txt',
|
||||
'https://ublockorigin.github.io/uAssets/thirdparties/urlhaus-filter/urlhaus-filter-online.txt',
|
||||
]
|
||||
],
|
||||
// Curben's Phishing URL Blocklist
|
||||
|
||||
Reference in New Issue
Block a user