@@ -82,7 +82,7 @@ const createClient = (profile, userAgent, opt = {}) => {
82
82
return _stationBoard ( station , 'ARR' , profile . parseArrival , opt )
83
83
}
84
84
85
- const journeys = ( from , to , opt = { } ) => {
85
+ const journeys = async ( from , to , opt = { } ) => {
86
86
from = profile . formatLocation ( profile , from , 'from' )
87
87
to = profile . formatLocation ( profile , to , 'to' )
88
88
@@ -173,75 +173,54 @@ const createClient = (profile, userAgent, opt = {}) => {
173
173
} )
174
174
}
175
175
176
- // With protocol version `1.16`, the VBB endpoint *used to* fail with
177
- // `CGI_READ_FAILED` if you pass `numF`, the parameter for the number
178
- // of results. To circumvent this, we loop here, collecting journeys
179
- // until we have enough.
180
- // todo: revert this change, see https://github.com/public-transport/hafas-client/issues/76#issuecomment-424448449
181
- const journeys = [ ]
182
- let earlierRef = null , laterRef = null
183
- const more = ( when , journeysRef ) => {
184
- const query = {
185
- getPasslist : ! ! opt . stopovers ,
186
- maxChg : opt . transfers ,
187
- minChgTime : opt . transferTime ,
188
- depLocL : [ from ] ,
189
- viaLocL : opt . via ? [ { loc : opt . via } ] : null ,
190
- arrLocL : [ to ] ,
191
- jnyFltrL : filters ,
192
- gisFltrL,
193
- getTariff : ! ! opt . tickets ,
194
- // todo: this is actually "take additional stations nearby the given start and destination station into account"
195
- // see rest.exe docs
196
- ushrp : ! ! opt . startWithWalking ,
197
-
198
- getPT : true , // todo: what is this?
199
- getIV : false , // todo: walk & bike as alternatives?
200
- getPolyline : ! ! opt . polylines
201
- // todo: `getConGroups: false` what is this?
202
- // todo: what is getEco, fwrd?
203
- }
204
- if ( journeysRef ) query . ctxScr = journeysRef
205
- else {
206
- query . outDate = profile . formatDate ( profile , when )
207
- query . outTime = profile . formatTime ( profile , when )
208
- }
209
- if ( profile . journeysNumF && opt . results !== null ) query . numF = opt . results
210
- if ( profile . journeysOutFrwd ) query . outFrwd = outFrwd
211
-
212
- return profile . request ( { profile, opt} , userAgent , {
213
- cfg : { polyEnc : 'GPA' } ,
214
- meth : 'TripSearch' ,
215
- req : profile . transformJourneysQuery ( { profile, opt} , query )
216
- } )
217
- . then ( ( { res, common} ) => {
218
- if ( ! Array . isArray ( res . outConL ) ) return [ ]
219
- // todo: outConGrpL
220
-
221
- const ctx = { profile, opt, common, res}
222
-
223
- if ( ! earlierRef ) earlierRef = res . outCtxScrB
176
+ const query = {
177
+ getPasslist : ! ! opt . stopovers ,
178
+ maxChg : opt . transfers ,
179
+ minChgTime : opt . transferTime ,
180
+ depLocL : [ from ] ,
181
+ viaLocL : opt . via ? [ { loc : opt . via } ] : null ,
182
+ arrLocL : [ to ] ,
183
+ jnyFltrL : filters ,
184
+ gisFltrL,
185
+ getTariff : ! ! opt . tickets ,
186
+ // todo: this is actually "take additional stations nearby the given start and destination station into account"
187
+ // see rest.exe docs
188
+ ushrp : ! ! opt . startWithWalking ,
189
+
190
+ getPT : true , // todo: what is this?
191
+ getIV : false , // todo: walk & bike as alternatives?
192
+ getPolyline : ! ! opt . polylines
193
+ // todo: `getConGroups: false` what is this?
194
+ // todo: what is getEco, fwrd?
195
+ }
196
+ if ( journeysRef ) query . ctxScr = journeysRef
197
+ else {
198
+ query . outDate = profile . formatDate ( profile , when )
199
+ query . outTime = profile . formatTime ( profile , when )
200
+ }
201
+ if ( profile . journeysNumF && opt . results !== null ) query . numF = opt . results
202
+ if ( profile . journeysOutFrwd ) query . outFrwd = outFrwd
203
+
204
+ const {
205
+ res, common,
206
+ } = await profile . request ( { profile, opt} , userAgent , {
207
+ cfg : { polyEnc : 'GPA' } ,
208
+ meth : 'TripSearch' ,
209
+ req : profile . transformJourneysQuery ( { profile, opt} , query )
210
+ } )
224
211
225
- let latestDep = - Infinity
226
- for ( const rawJourney of res . outConL ) {
227
- const journey = profile . parseJourney ( ctx , rawJourney )
228
- journeys . push ( journey )
212
+ if ( ! Array . isArray ( res . outConL ) ) return [ ]
213
+ // todo: outConGrpL
229
214
230
- if ( opt . results !== null && journeys . length >= opt . results ) { // collected enough
231
- laterRef = res . outCtxScrF
232
- return { earlierRef, laterRef, journeys}
233
- }
234
- const dep = + new Date ( journey . legs [ 0 ] . departure ) // todo
235
- if ( dep > latestDep ) latestDep = dep
236
- }
215
+ const ctx = { profile, opt, common, res}
216
+ const journeys = res . outConL
217
+ . map ( j => profile . parseJourney ( ctx , j ) )
237
218
238
- if ( opt . results === null ) return { earlierRef , laterRef , journeys }
239
- const when = new Date ( latestDep )
240
- return more ( when , res . outCtxScrF ) // otherwise continue
241
- } )
219
+ return {
220
+ earlierRef : res . outCtxScrB ,
221
+ laterRef : res . outCtxScrF ,
222
+ journeys ,
242
223
}
243
-
244
- return more ( when , journeysRef )
245
224
}
246
225
247
226
const refreshJourney = ( refreshToken , opt = { } ) => {
0 commit comments