mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 15:19:35 +02:00
VBB: circumvent CGI_READ_FAILD if numF is used 🐛
This commit is contained in:
parent
9f37335327
commit
7fd574f0f8
1 changed files with 87 additions and 32 deletions
77
index.js
77
index.js
|
@ -101,11 +101,16 @@ const createClient = (profile, request = _request) => {
|
||||||
filters.push(profile.filters.accessibility[opt.accessibility])
|
filters.push(profile.filters.accessibility[opt.accessibility])
|
||||||
}
|
}
|
||||||
|
|
||||||
const query = profile.transformJourneysQuery({
|
// With protocol version `1.16`, the VBB endpoint fails with
|
||||||
outDate: profile.formatDate(profile, opt.when),
|
// `CGI_READ_FAILED` if you pass `numF`, the parameter for the number
|
||||||
outTime: profile.formatTime(profile, opt.when),
|
// of results. To circumvent this, we loop here, collecting journeys
|
||||||
ctxScr: journeysRef,
|
// until we have enough.
|
||||||
numF: opt.results,
|
// see https://github.com/derhuerst/hafas-client/pull/23#issuecomment-370246163
|
||||||
|
// todo: check if `numF` is supported again, revert this change
|
||||||
|
const journeys = []
|
||||||
|
const more = (when, journeysRef) => {
|
||||||
|
const query = {
|
||||||
|
// numF: opt.results,
|
||||||
getPasslist: !!opt.passedStations,
|
getPasslist: !!opt.passedStations,
|
||||||
maxChg: opt.transfers,
|
maxChg: opt.transfers,
|
||||||
minChgTime: opt.transferTime,
|
minChgTime: opt.transferTime,
|
||||||
|
@ -120,24 +125,74 @@ const createClient = (profile, request = _request) => {
|
||||||
outFrwd: true, // todo: what is this?
|
outFrwd: true, // todo: what is this?
|
||||||
getIV: false, // todo: walk & bike as alternatives?
|
getIV: false, // todo: walk & bike as alternatives?
|
||||||
getPolyline: false // todo: shape for displaying on a map?
|
getPolyline: false // todo: shape for displaying on a map?
|
||||||
}, opt)
|
}
|
||||||
|
if (when) {
|
||||||
|
query.outDate = profile.formatDate(profile, when)
|
||||||
|
query.outTime = profile.formatTime(profile, when)
|
||||||
|
} else if (journeysRef) {
|
||||||
|
query.ctxScr = journeysRef
|
||||||
|
} else throw new Error('when or ref required')
|
||||||
|
|
||||||
return request(profile, {
|
return request(profile, {
|
||||||
cfg: {polyEnc: 'GPA'},
|
cfg: {polyEnc: 'GPA'},
|
||||||
meth: 'TripSearch',
|
meth: 'TripSearch',
|
||||||
req: query
|
req: profile.transformJourneysQuery(query, opt)
|
||||||
})
|
})
|
||||||
.then((d) => {
|
.then((d) => {
|
||||||
if (!Array.isArray(d.outConL)) return []
|
if (!Array.isArray(d.outConL)) return []
|
||||||
const parse = profile.parseJourney(profile, d.locations, d.lines, d.remarks)
|
const parse = profile.parseJourney(profile, d.locations, d.lines, d.remarks)
|
||||||
const res = d.outConL.map(parse)
|
if (!journeys.earlierRef) journeys.earlierRef = d.outCtxScrB
|
||||||
|
|
||||||
if (d.outCtxScrB) res.earlierRef = d.outCtxScrB
|
for (let j of d.outConL) {
|
||||||
if (d.outCtxScrF) res.laterRef = d.outCtxScrF
|
journeys.push(parse(j))
|
||||||
return res
|
if (journeys.length === opt.results) { // collected enough
|
||||||
|
journeys.laterRef = d.outCtxScrF
|
||||||
|
return journeys
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return more(null, d.outCtxScrF) // otherwise continue
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return more(opt.when, journeysRef)
|
||||||
|
|
||||||
|
// const query = profile.transformJourneysQuery({
|
||||||
|
// outDate: profile.formatDate(profile, opt.when),
|
||||||
|
// outTime: profile.formatTime(profile, opt.when),
|
||||||
|
// ctxScr: journeysRef,
|
||||||
|
// numF: opt.results,
|
||||||
|
// getPasslist: !!opt.passedStations,
|
||||||
|
// maxChg: opt.transfers,
|
||||||
|
// minChgTime: opt.transferTime,
|
||||||
|
// depLocL: [from],
|
||||||
|
// viaLocL: opt.via ? [{loc: opt.via}] : null,
|
||||||
|
// arrLocL: [to],
|
||||||
|
// jnyFltrL: filters,
|
||||||
|
// getTariff: !!opt.tickets,
|
||||||
|
|
||||||
|
// // todo: what is req.gisFltrL?
|
||||||
|
// getPT: true, // todo: what is this?
|
||||||
|
// outFrwd: true, // todo: what is this?
|
||||||
|
// getIV: false, // todo: walk & bike as alternatives?
|
||||||
|
// getPolyline: false // todo: shape for displaying on a map?
|
||||||
|
// }, opt)
|
||||||
|
|
||||||
|
// return request(profile, {
|
||||||
|
// cfg: {polyEnc: 'GPA'},
|
||||||
|
// meth: 'TripSearch',
|
||||||
|
// req: query
|
||||||
|
// })
|
||||||
|
// .then((d) => {
|
||||||
|
// if (!Array.isArray(d.outConL)) return []
|
||||||
|
// const parse = profile.parseJourney(profile, d.locations, d.lines, d.remarks)
|
||||||
|
// const res = d.outConL.map(parse)
|
||||||
|
|
||||||
|
// if (d.outCtxScrB) res.earlierRef = d.outCtxScrB
|
||||||
|
// if (d.outCtxScrF) res.laterRef = d.outCtxScrF
|
||||||
|
// return res
|
||||||
|
// })
|
||||||
|
}
|
||||||
|
|
||||||
const locations = (query, opt = {}) => {
|
const locations = (query, opt = {}) => {
|
||||||
if (!isNonEmptyString(query)) {
|
if (!isNonEmptyString(query)) {
|
||||||
throw new Error('query must be a non-empty string.')
|
throw new Error('query must be a non-empty string.')
|
||||||
|
|
Loading…
Add table
Reference in a new issue