@@ -29,11 +29,11 @@ import {
29
29
IntervalTime ,
30
30
StartPollingConfig
31
31
} from './types/api'
32
- import { XCrawlBaseConifg } from './types'
32
+ import { LoaderXCrawlBaseConifg } from './types'
33
33
import { RequestConfig , RequestResItem } from './types/request'
34
34
35
35
function mergeConfig < T extends FetchBaseConifgV1 > (
36
- baseConfig : XCrawlBaseConifg ,
36
+ baseConfig : LoaderXCrawlBaseConifg ,
37
37
rawConfig : T
38
38
) : T {
39
39
const newConfig = structuredClone ( rawConfig )
@@ -70,7 +70,7 @@ function mergeConfig<T extends FetchBaseConifgV1>(
70
70
}
71
71
72
72
async function useBatchRequestByMode (
73
- mode : 'async' | 'sync' | undefined ,
73
+ mode : 'async' | 'sync' ,
74
74
requestConifg : RequestConfig | RequestConfig [ ] ,
75
75
intervalTime : IntervalTime | undefined ,
76
76
callback : ( requestRestem : RequestResItem ) => void
@@ -79,14 +79,14 @@ async function useBatchRequestByMode(
79
79
? requestConifg
80
80
: [ requestConifg ]
81
81
82
- if ( mode !== 'sync ') {
82
+ if ( mode === 'async ') {
83
83
await batchRequest ( requestConfigQueue , intervalTime , callback )
84
84
} else {
85
85
await syncBatchRequest ( requestConfigQueue , intervalTime , callback )
86
86
}
87
87
}
88
88
89
- export function createFetchHTML ( baseConfig : XCrawlBaseConifg ) {
89
+ export function createFetchHTML ( baseConfig : LoaderXCrawlBaseConifg ) {
90
90
let browser : Browser | null = null
91
91
let createBrowserState : Promise < void > | null = null
92
92
let callTotal = 0
@@ -95,7 +95,7 @@ export function createFetchHTML(baseConfig: XCrawlBaseConifg) {
95
95
config : FetchHTMLConfig ,
96
96
callback ?: ( res : FetchHTML ) => void
97
97
) : Promise < FetchHTML > {
98
- // 记录调用次数, 为关闭浏览器
98
+ // 记录调用次数, 目的: 关闭浏览器
99
99
callTotal ++
100
100
101
101
// 只创建一次浏览器
@@ -129,22 +129,20 @@ export function createFetchHTML(baseConfig: XCrawlBaseConifg) {
129
129
} )
130
130
}
131
131
132
- const httpResponse = await page ! . goto ( requestConifg . url )
132
+ const httpResponse = await page ! . goto ( requestConifg . url , {
133
+ timeout : requestConifg . timeout
134
+ } )
133
135
134
136
const content = await page ! . content ( )
135
137
136
138
// 关闭浏览器
137
139
if ( -- callTotal === 0 ) {
138
- await browser ! . close ( )
140
+ browser ! . close ( )
139
141
}
140
142
141
143
const res : FetchHTML = {
142
144
httpResponse,
143
- data : {
144
- page,
145
- content,
146
- jsdom : new JSDOM ( content )
147
- }
145
+ data : { page, jsdom : new JSDOM ( content ) }
148
146
}
149
147
150
148
if ( callback ) {
@@ -157,7 +155,7 @@ export function createFetchHTML(baseConfig: XCrawlBaseConifg) {
157
155
return fetchHTML
158
156
}
159
157
160
- export function createFetchData ( baseConfig : XCrawlBaseConifg ) {
158
+ export function createFetchData ( baseConfig : LoaderXCrawlBaseConifg ) {
161
159
async function fetchData < T = any > (
162
160
config : FetchDataConfig ,
163
161
callback ?: ( res : FetchResCommonV1 < T > ) => void
@@ -198,7 +196,7 @@ export function createFetchData(baseConfig: XCrawlBaseConifg) {
198
196
return fetchData
199
197
}
200
198
201
- export function createFetchFile ( baseConfig : XCrawlBaseConifg ) {
199
+ export function createFetchFile ( baseConfig : LoaderXCrawlBaseConifg ) {
202
200
async function fetchFile (
203
201
config : FetchFileConfig ,
204
202
callback ?: ( res : FetchResCommonV1 < FileInfo > ) => void
0 commit comments