diff --git a/src/lib/common/BaseAPI.ts b/src/lib/common/BaseAPI.ts index 8ee235c..dbe294a 100644 --- a/src/lib/common/BaseAPI.ts +++ b/src/lib/common/BaseAPI.ts @@ -1,4 +1,3 @@ -import { Response } from 'node-fetch'; import Cache from '../utils/Cache.js'; import Fetcher, { FetchMethod } from '../utils/Fetcher.js'; @@ -17,7 +16,7 @@ export default abstract class BaseAPI { this.#cache = params.cache; } - protected fetch(url: string, jsonResponse: false, method: FetchMethod.HEAD, payload?: undefined): Promise; + protected fetch(url: string, jsonResponse: false, method: FetchMethod.HEAD, payload?: undefined): Promise<{ ok: boolean, status: number }>; protected fetch(url: string, jsonResponse: true, method?: FetchMethod, payload?: Record): Promise; protected fetch(url: string, jsonResponse?: boolean, method?: FetchMethod, payload?: Record): Promise; protected fetch(url: string, jsonResponse?: boolean, method?: FetchMethod, payload?: Record): Promise { diff --git a/src/lib/stream/StreamAPI.ts b/src/lib/stream/StreamAPI.ts index 2410a7b..af73b86 100644 --- a/src/lib/stream/StreamAPI.ts +++ b/src/lib/stream/StreamAPI.ts @@ -11,11 +11,7 @@ export interface StreamTestResult { export default class StreamAPI extends BaseAPI { async test(url: string): Promise { - const res = await this.fetch(url, false, FetchMethod.HEAD); - return { - ok: res.ok, - status: res.status - }; + return this.fetch(url, false, FetchMethod.HEAD); } async refresh(url: string): Promise { diff --git a/src/lib/utils/Fetcher.ts b/src/lib/utils/Fetcher.ts index cea0970..7687be7 100644 --- a/src/lib/utils/Fetcher.ts +++ b/src/lib/utils/Fetcher.ts @@ -35,7 +35,7 @@ export default class Fetcher { return this.#cookie; } - fetch(url: string, jsonResponse: false, method: FetchMethod.HEAD, payload?: undefined): Promise; + fetch(url: string, jsonResponse: false, method: FetchMethod.HEAD, payload?: undefined): Promise<{ ok: boolean, status: number }>; fetch(url: string, jsonResponse: true, method?: FetchMethod, payload?: Record): Promise; fetch(url: string, jsonResponse?: boolean, method?: FetchMethod, payload?: Record): Promise; fetch(url: string, jsonResponse?: boolean, method?: FetchMethod, payload?: Record) { @@ -48,7 +48,11 @@ export default class Fetcher { } if (method === FetchMethod.HEAD) { - return fetch(url, { method: 'HEAD' }); + const response = await fetch(url, { method: 'HEAD' }); + return { + ok: response.ok, + status: response.status + }; } let response;