@@ -12,6 +12,8 @@ import {
12
12
isUndefined ,
13
13
log ,
14
14
logError ,
15
+ logStart ,
16
+ logStatistics ,
15
17
logSuccess ,
16
18
logWarn ,
17
19
mkdirDirSync ,
@@ -40,35 +42,29 @@ import { fingerprints } from './default'
40
42
41
43
// Extra config
42
44
export interface ExtraCommonConfig {
43
- intervalTime : IntervalTime | undefined
44
- }
45
+ type : 'page' | 'data' | 'file'
45
46
46
- export interface ExtraDataAndFileCommonConfig {
47
- type : 'data' | 'file'
47
+ intervalTime : IntervalTime | undefined
48
48
}
49
49
50
50
interface ExtraPageConfig extends ExtraCommonConfig {
51
51
browser : Browser
52
52
onCrawlItemComplete :
53
- | ( ( crawlPageSingleRes : CrawlPageSingleResult ) => void )
53
+ | ( ( crawlPageSingleResult : CrawlPageSingleResult ) => void )
54
54
| undefined
55
55
}
56
56
57
- interface ExtraDataConfig < T >
58
- extends ExtraCommonConfig ,
59
- ExtraDataAndFileCommonConfig {
57
+ interface ExtraDataConfig < T > extends ExtraCommonConfig {
60
58
onCrawlItemComplete :
61
- | ( ( crawlDataSingleRes : CrawlDataSingleResult < T > ) => void )
59
+ | ( ( crawlDataSingleResult : CrawlDataSingleResult < T > ) => void )
62
60
| undefined
63
61
}
64
62
65
- interface ExtraFileConfig
66
- extends ExtraCommonConfig ,
67
- ExtraDataAndFileCommonConfig {
63
+ interface ExtraFileConfig extends ExtraCommonConfig {
68
64
saveFileErrorArr : { message : string ; valueOf : ( ) => number } [ ]
69
65
saveFilePendingQueue : Promise < any > [ ]
70
66
onCrawlItemComplete :
71
- | ( ( crawlFileSingleRes : CrawlFileSingleResult ) => void )
67
+ | ( ( crawlFileSingleResult : CrawlFileSingleResult ) => void )
72
68
| undefined
73
69
onBeforeSaveItemFile :
74
70
| ( ( info : {
@@ -135,7 +131,7 @@ interface CrawlPageConfig {
135
131
selectFingerprintIndexs : number [ ]
136
132
137
133
onCrawlItemComplete :
138
- | ( ( crawlPageSingleRes : CrawlPageSingleResult ) => void )
134
+ | ( ( crawlPageSingleResult : CrawlPageSingleResult ) => void )
139
135
| undefined
140
136
}
141
137
@@ -146,7 +142,7 @@ interface CrawlDataConfig {
146
142
selectFingerprintIndexs : number [ ]
147
143
148
144
onCrawlItemComplete :
149
- | ( ( crawlDataSingleRes : CrawlDataSingleResult < any > ) => void )
145
+ | ( ( crawlDataSingleResult : CrawlDataSingleResult < any > ) => void )
150
146
| undefined
151
147
}
152
148
@@ -165,7 +161,7 @@ interface CrawlFileConfig {
165
161
} ) => Promise < Buffer > )
166
162
| undefined
167
163
onCrawlItemComplete :
168
- | ( ( crawlDataSingleRes : CrawlDataSingleResult < any > ) => void )
164
+ | ( ( crawlDataSingleResult : CrawlDataSingleResult < any > ) => void )
169
165
| undefined
170
166
}
171
167
@@ -983,13 +979,14 @@ export function createCrawlPage(xCrawlConfig: LoaderXCrawlConfig) {
983
979
createCrawlPageConfig ( xCrawlConfig , config )
984
980
985
981
const extraConfig : ExtraPageConfig = {
982
+ type : 'page' ,
983
+
986
984
browser : browser ! ,
987
985
intervalTime,
988
986
onCrawlItemComplete
989
987
}
990
988
991
989
const crawlResultArr = ( await controller (
992
- 'page' ,
993
990
xCrawlConfig . mode ,
994
991
detailTargets ,
995
992
extraConfig ,
@@ -1046,7 +1043,6 @@ export function createCrawlData(xCrawlConfig: LoaderXCrawlConfig) {
1046
1043
}
1047
1044
1048
1045
const crawlResultArr = ( await controller (
1049
- 'data' ,
1050
1046
xCrawlConfig . mode ,
1051
1047
detailTargets ,
1052
1048
extraConfig ,
@@ -1107,7 +1103,6 @@ export function createCrawlFile(xCrawlConfig: LoaderXCrawlConfig) {
1107
1103
}
1108
1104
1109
1105
const crawlResultArr = ( await controller (
1110
- 'file' ,
1111
1106
xCrawlConfig . mode ,
1112
1107
detailTargets ,
1113
1108
extraConfig ,
@@ -1132,19 +1127,19 @@ export function createCrawlFile(xCrawlConfig: LoaderXCrawlConfig) {
1132
1127
errorIds . push ( item . id )
1133
1128
}
1134
1129
} )
1135
- log ( 'Save statistics for the targets:' )
1130
+ log ( logStatistics ( 'Save files finish:' ) )
1136
1131
log (
1137
1132
logSuccess (
1138
- ` Success - target total: ${
1139
- succssIds . length
1140
- } , targets id: [ ${ succssIds . join ( ', ' ) } ]`
1133
+ ` Success - total: ${ succssIds . length } , targets id: [ ${ succssIds . join (
1134
+ ', '
1135
+ ) } ]`
1141
1136
)
1142
1137
)
1143
1138
log (
1144
1139
logError (
1145
- ` Error - target total: ${
1146
- errorIds . length
1147
- } , targets id: [ ${ errorIds . join ( ', ' ) } ]`
1140
+ ` Error - total: ${ errorIds . length } , targets id: [ ${ errorIds . join (
1141
+ ', '
1142
+ ) } ]`
1148
1143
)
1149
1144
)
1150
1145
@@ -1180,13 +1175,13 @@ export function startPolling(
1180
1175
const intervalId = setInterval ( startCallback , total )
1181
1176
1182
1177
function startCallback ( ) {
1183
- console . log ( logSuccess ( `Start the ${ logWarn . bold ( ++ count ) } polling ` ) )
1178
+ console . log ( logStart ( `Start polling - count: ${ ++ count } ` ) )
1184
1179
1185
1180
callback ( count , stopPolling )
1186
1181
}
1187
1182
1188
1183
function stopPolling ( ) {
1189
1184
clearInterval ( intervalId )
1190
- console . log ( logSuccess ( `Stop the polling` ) )
1185
+ console . log ( logWarn ( `Stop the polling` ) )
1191
1186
}
1192
1187
}
0 commit comments