@@ -29,11 +29,11 @@ import {
2929 IntervalTime ,
3030 StartPollingConfig
3131} from './types/api'
32- import { XCrawlBaseConifg } from './types'
32+ import { LoaderXCrawlBaseConifg } from './types'
3333import { RequestConfig , RequestResItem } from './types/request'
3434
3535function mergeConfig < T extends FetchBaseConifgV1 > (
36- baseConfig : XCrawlBaseConifg ,
36+ baseConfig : LoaderXCrawlBaseConifg ,
3737 rawConfig : T
3838) : T {
3939 const newConfig = structuredClone ( rawConfig )
@@ -70,7 +70,7 @@ function mergeConfig<T extends FetchBaseConifgV1>(
7070}
7171
7272async function useBatchRequestByMode (
73- mode : 'async' | 'sync' | undefined ,
73+ mode : 'async' | 'sync' ,
7474 requestConifg : RequestConfig | RequestConfig [ ] ,
7575 intervalTime : IntervalTime | undefined ,
7676 callback : ( requestRestem : RequestResItem ) => void
@@ -79,14 +79,14 @@ async function useBatchRequestByMode(
7979 ? requestConifg
8080 : [ requestConifg ]
8181
82- if ( mode !== 'sync ') {
82+ if ( mode === 'async ') {
8383 await batchRequest ( requestConfigQueue , intervalTime , callback )
8484 } else {
8585 await syncBatchRequest ( requestConfigQueue , intervalTime , callback )
8686 }
8787}
8888
89- export function createFetchHTML ( baseConfig : XCrawlBaseConifg ) {
89+ export function createFetchHTML ( baseConfig : LoaderXCrawlBaseConifg ) {
9090 let browser : Browser | null = null
9191 let createBrowserState : Promise < void > | null = null
9292 let callTotal = 0
@@ -95,7 +95,7 @@ export function createFetchHTML(baseConfig: XCrawlBaseConifg) {
9595 config : FetchHTMLConfig ,
9696 callback ?: ( res : FetchHTML ) => void
9797 ) : Promise < FetchHTML > {
98- // 记录调用次数, 为关闭浏览器
98+ // 记录调用次数, 目的: 关闭浏览器
9999 callTotal ++
100100
101101 // 只创建一次浏览器
@@ -129,22 +129,20 @@ export function createFetchHTML(baseConfig: XCrawlBaseConifg) {
129129 } )
130130 }
131131
132- const httpResponse = await page ! . goto ( requestConifg . url )
132+ const httpResponse = await page ! . goto ( requestConifg . url , {
133+ timeout : requestConifg . timeout
134+ } )
133135
134136 const content = await page ! . content ( )
135137
136138 // 关闭浏览器
137139 if ( -- callTotal === 0 ) {
138- await browser ! . close ( )
140+ browser ! . close ( )
139141 }
140142
141143 const res : FetchHTML = {
142144 httpResponse,
143- data : {
144- page,
145- content,
146- jsdom : new JSDOM ( content )
147- }
145+ data : { page, jsdom : new JSDOM ( content ) }
148146 }
149147
150148 if ( callback ) {
@@ -157,7 +155,7 @@ export function createFetchHTML(baseConfig: XCrawlBaseConifg) {
157155 return fetchHTML
158156}
159157
160- export function createFetchData ( baseConfig : XCrawlBaseConifg ) {
158+ export function createFetchData ( baseConfig : LoaderXCrawlBaseConifg ) {
161159 async function fetchData < T = any > (
162160 config : FetchDataConfig ,
163161 callback ?: ( res : FetchResCommonV1 < T > ) => void
@@ -198,7 +196,7 @@ export function createFetchData(baseConfig: XCrawlBaseConifg) {
198196 return fetchData
199197}
200198
201- export function createFetchFile ( baseConfig : XCrawlBaseConifg ) {
199+ export function createFetchFile ( baseConfig : LoaderXCrawlBaseConifg ) {
202200 async function fetchFile (
203201 config : FetchFileConfig ,
204202 callback ?: ( res : FetchResCommonV1 < FileInfo > ) => void
0 commit comments