mirror of
https://github.com/SukkaW/Surge.git
synced 2026-02-03 12:31:54 +08:00
Refactor: migrate to undici fetch
This commit is contained in:
@@ -8,7 +8,6 @@ import { TextLineStream } from './text-line-transform-stream';
|
||||
import type { ReadableStream } from 'node:stream/web';
|
||||
import { TextDecoderStream } from 'node:stream/web';
|
||||
import { processLine, ProcessLineStream } from './process-line';
|
||||
import type { NodeFetchResponse } from './make-fetch-happen';
|
||||
import { $$fetch } from './fetch-retry';
|
||||
import type { UndiciResponseData } from './fetch-retry';
|
||||
import type { Response as UnidiciWebResponse } from 'undici';
|
||||
@@ -38,7 +37,7 @@ export async function readFileByLineNew(file: string): Promise<AsyncIterable<str
|
||||
return fsp.open(file, 'r').then(fdReadLines);
|
||||
}
|
||||
|
||||
function ensureResponseBody<T extends NodeFetchResponse | UndiciResponseData | UnidiciWebResponse>(resp: T): NonNullable<T['body']> {
|
||||
function ensureResponseBody<T extends UndiciResponseData | UnidiciWebResponse>(resp: T): NonNullable<T['body']> {
|
||||
if (resp.body == null) {
|
||||
throw new Error('Failed to fetch remote text');
|
||||
}
|
||||
@@ -48,7 +47,7 @@ function ensureResponseBody<T extends NodeFetchResponse | UndiciResponseData | U
|
||||
return resp.body;
|
||||
}
|
||||
|
||||
export const createReadlineInterfaceFromResponse: ((resp: NodeFetchResponse | UndiciResponseData | UnidiciWebResponse, processLine?: boolean) => ReadableStream<string>) = (resp, processLine = false) => {
|
||||
export const createReadlineInterfaceFromResponse: ((resp: UndiciResponseData | UnidiciWebResponse, processLine?: boolean) => ReadableStream<string>) = (resp, processLine = false) => {
|
||||
const stream = ensureResponseBody(resp);
|
||||
|
||||
const webStream: ReadableStream<Uint8Array> = 'getReader' in stream
|
||||
|
||||
Reference in New Issue
Block a user