Skip to content

Commit 53bf5d5

Browse files
committed
fetchData and fetchFile request handling
1 parent c59548c commit 53bf5d5

File tree

7 files changed

+193
-122
lines changed

7 files changed

+193
-122
lines changed

README.md

+29-27
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ Create a crawler instance via new XCrawl.
4545
class XCrawl {
4646
private readonly baseConfig
4747
constructor(baseConfig?: IXCrawlBaseConifg)
48-
fetchData<T = any>(config: IFetchDataConfig): Promise<IFetchData<T>>
49-
fetchFile(config: IFetchFileConfig): Promise<IFetchFile>
48+
fetchData<T = any>(config: IFetchDataConfig): Promise<IFetchCommon<T>>
49+
fetchFile(config: IFetchFileConfig): Promise<IFetchCommon<IFileInfo>>
5050
fetchHTML(url: string): Promise<JSDOM>
5151
}
5252
```
@@ -74,7 +74,7 @@ fetchData is the method of the above <a href="#myXCrawl" style="text-decoration:
7474
- Type
7575
7676
```ts
77-
function fetchData <T = any>(config: IFetchDataConfig): Promise<T>
77+
function fetchData<T = any>(config: IFetchDataConfig): Promise<IFetchCommon<T>>
7878
```
7979

8080
- Example
@@ -101,7 +101,7 @@ fetchFile is the method of the above <a href="#myXCrawl" style="text-decoration
101101
- Type
102102
103103
```ts
104-
function fetchFile(config: IFetchFileConfig): Promise<IFetchFile>
104+
function fetchFile(config: IFetchFileConfig): Promise<IFetchCommon<IFileInfo>>
105105
```
106106

107107
- Example
@@ -153,14 +153,14 @@ interface IAnyObject extends Object {
153153
154154
- IMethod
155155
156-
```ts
157-
export type IMethod = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK'
156+
```ts
157+
type IMethod = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK'
158158
```
159159
160160
- IRequestConfig
161161
162162
```ts
163-
export interface IRequestConfig {
163+
interface IRequestConfig {
164164
url: string
165165
method?: IMethod
166166
headers?: IAnyObject
@@ -188,25 +188,26 @@ interface IFetchBaseConifg {
188188
}
189189
```
190190
191-
- IFechData
191+
- IFetchCommon
192192
193193
```ts
194-
type IFetchData<T> = {
194+
type IFetchCommon<T> = {
195+
id: number
195196
statusCode: number | undefined
196-
headers: IncomingHttpHeaders // node:http
197+
headers: IncomingHttpHeaders // node:http type
197198
data: T
198199
}[]
199200
```
200201
201-
- IFetchFile
202+
- IFileInfo
202203
203204
```ts
204-
type IFetchFile = {
205+
IFileInfo {
205206
fileName: string
206207
mimeType: string
207208
size: number
208209
filePath: string
209-
}[]
210+
}
210211
```
211212
212213
- IXCrawlBaseConifg
@@ -238,7 +239,7 @@ interface IFetchFileConfig extends IFetchBaseConifg {
238239
239240
## More
240241
241-
If you have any **questions** or **needs** , please submit **Issues in** https://github.com/coder-hxl/x-crawl .
242+
If you have any **questions** or **needs** , please submit **Issues in** https://github.com/coder-hxl/x-crawl/issues .
242243
243244
244245
---
@@ -291,8 +292,8 @@ docsXCrawl.fetchHTML('/zh/get-started').then((jsdom) => {
291292
class XCrawl {
292293
private readonly baseConfig
293294
constructor(baseConfig?: IXCrawlBaseConifg)
294-
fetchData<T = any>(config: IFetchDataConfig): Promise<IFetchData<T>>
295-
fetchFile(config: IFetchFileConfig): Promise<IFetchFile>
295+
fetchData<T = any>(config: IFetchDataConfig): Promise<IFetchCommon<T>>
296+
fetchFile(config: IFetchFileConfig): Promise<IFetchCommon<IFileInfo>>
296297
fetchHTML(url: string): Promise<JSDOM>
297298
}
298299
```
@@ -320,7 +321,7 @@ fetch 是上面 <a href="#cn-myXCrawl" style="text-decoration: none">myXCrawl</
320321
- 类型
321322

322323
```ts
323-
function fetchData<T = any>(config: IFetchDataConfig): Promise<T>
324+
function fetchData<T = any>(config: IFetchDataConfig): Promise<IFetchCommon<T>>
324325
```
325326

326327
- 示例
@@ -347,7 +348,7 @@ fetchFile 是上面 <a href="#cn-myXCrawl" style="text-decoration: none">myXCra
347348
- 类型
348349

349350
```ts
350-
function fetchFile(config: IFetchFileConfig): Promise<IFetchFile>
351+
function fetchFile(config: IFetchFileConfig): Promise<IFetchCommon<IFileInfo>>
351352
```
352353

353354
- 示例
@@ -400,13 +401,13 @@ interface IAnyObject extends Object {
400401
- IMethod
401402

402403
```ts
403-
export type IMethod = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK'
404+
type IMethod = 'get' | 'GET' | 'delete' | 'DELETE' | 'head' | 'HEAD' | 'options' | 'OPTIONS' | 'post' | 'POST' | 'put' | 'PUT' | 'patch' | 'PATCH' | 'purge' | 'PURGE' | 'link' | 'LINK' | 'unlink' | 'UNLINK'
404405
```
405406

406407
- IRequestConfig
407408

408409
```ts
409-
export interface IRequestConfig {
410+
interface IRequestConfig {
410411
url: string
411412
method?: IMethod
412413
headers?: IAnyObject
@@ -434,25 +435,26 @@ interface IFetchBaseConifg {
434435
}
435436
```
436437

437-
- IFetchData
438+
- IFetchCommon
438439

439440
```ts
440-
type IFetch<T> = {
441+
type IFetchCommon<T> = {
442+
id: number
441443
statusCode: number | undefined
442-
headers: IncomingHttpHeaders // node:http
444+
headers: IncomingHttpHeaders // node:http type
443445
data: T
444446
}[]
445447
```
446448

447-
- IFetchFile
449+
- IFileInfo
448450

449451
```ts
450-
type IFetchFile = {
452+
interface IFileInfo {
451453
fileName: string
452454
mimeType: string
453455
size: number
454456
filePath: string
455-
}[]
457+
}
456458
```
457459

458460
- IXCrawlBaseConifg
@@ -484,4 +486,4 @@ interface IFetchFileConfig extends IFetchBaseConifg {
484486

485487
## 更多
486488

487-
如有 **问题****需求** 请在 https://github.com/coder-hxl/x-crawl 中提 **Issues** 。
489+
如有 **问题****需求** 请在 https://github.com/coder-hxl/x-crawl/issues 中提 **Issues** 。

0 commit comments

Comments
 (0)