mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-04-20 23:23:56 +03:00
journeys: remove collection of results
Reverts 7fd574f
.
See also https://github.com/public-transport/hafas-client/pull/23#issuecomment-370246163 .
This commit is contained in:
parent
5c05375650
commit
51f4a66bd8
4 changed files with 46 additions and 70 deletions
43
index.js
43
index.js
|
@ -82,7 +82,7 @@ const createClient = (profile, userAgent, opt = {}) => {
|
||||||
return _stationBoard(station, 'ARR', profile.parseArrival, opt)
|
return _stationBoard(station, 'ARR', profile.parseArrival, opt)
|
||||||
}
|
}
|
||||||
|
|
||||||
const journeys = (from, to, opt = {}) => {
|
const journeys = async (from, to, opt = {}) => {
|
||||||
from = profile.formatLocation(profile, from, 'from')
|
from = profile.formatLocation(profile, from, 'from')
|
||||||
to = profile.formatLocation(profile, to, 'to')
|
to = profile.formatLocation(profile, to, 'to')
|
||||||
|
|
||||||
|
@ -173,14 +173,6 @@ const createClient = (profile, userAgent, opt = {}) => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// With protocol version `1.16`, the VBB endpoint *used to* fail with
|
|
||||||
// `CGI_READ_FAILED` if you pass `numF`, the parameter for the number
|
|
||||||
// of results. To circumvent this, we loop here, collecting journeys
|
|
||||||
// until we have enough.
|
|
||||||
// todo: revert this change, see https://github.com/public-transport/hafas-client/issues/76#issuecomment-424448449
|
|
||||||
const journeys = []
|
|
||||||
let earlierRef = null, laterRef = null
|
|
||||||
const more = (when, journeysRef) => {
|
|
||||||
const query = {
|
const query = {
|
||||||
getPasslist: !!opt.stopovers,
|
getPasslist: !!opt.stopovers,
|
||||||
maxChg: opt.transfers,
|
maxChg: opt.transfers,
|
||||||
|
@ -209,39 +201,26 @@ const createClient = (profile, userAgent, opt = {}) => {
|
||||||
if (profile.journeysNumF && opt.results !== null) query.numF = opt.results
|
if (profile.journeysNumF && opt.results !== null) query.numF = opt.results
|
||||||
if (profile.journeysOutFrwd) query.outFrwd = outFrwd
|
if (profile.journeysOutFrwd) query.outFrwd = outFrwd
|
||||||
|
|
||||||
return profile.request({profile, opt}, userAgent, {
|
const {
|
||||||
|
res, common,
|
||||||
|
} = await profile.request({profile, opt}, userAgent, {
|
||||||
cfg: {polyEnc: 'GPA'},
|
cfg: {polyEnc: 'GPA'},
|
||||||
meth: 'TripSearch',
|
meth: 'TripSearch',
|
||||||
req: profile.transformJourneysQuery({profile, opt}, query)
|
req: profile.transformJourneysQuery({profile, opt}, query)
|
||||||
})
|
})
|
||||||
.then(({res, common}) => {
|
|
||||||
if (!Array.isArray(res.outConL)) return []
|
if (!Array.isArray(res.outConL)) return []
|
||||||
// todo: outConGrpL
|
// todo: outConGrpL
|
||||||
|
|
||||||
const ctx = {profile, opt, common, res}
|
const ctx = {profile, opt, common, res}
|
||||||
|
const journeys = res.outConL
|
||||||
|
.map(j => profile.parseJourney(ctx, j))
|
||||||
|
|
||||||
if (!earlierRef) earlierRef = res.outCtxScrB
|
return {
|
||||||
|
earlierRef: res.outCtxScrB,
|
||||||
let latestDep = -Infinity
|
laterRef: res.outCtxScrF,
|
||||||
for (const rawJourney of res.outConL) {
|
journeys,
|
||||||
const journey = profile.parseJourney(ctx, rawJourney)
|
|
||||||
journeys.push(journey)
|
|
||||||
|
|
||||||
if (opt.results !== null && journeys.length >= opt.results) { // collected enough
|
|
||||||
laterRef = res.outCtxScrF
|
|
||||||
return {earlierRef, laterRef, journeys}
|
|
||||||
}
|
}
|
||||||
const dep = +new Date(journey.legs[0].departure) // todo
|
|
||||||
if (dep > latestDep) latestDep = dep
|
|
||||||
}
|
|
||||||
|
|
||||||
if (opt.results === null) return {earlierRef, laterRef, journeys}
|
|
||||||
const when = new Date(latestDep)
|
|
||||||
return more(when, res.outCtxScrF) // otherwise continue
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return more(when, journeysRef)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const refreshJourney = (refreshToken, opt = {}) => {
|
const refreshJourney = (refreshToken, opt = {}) => {
|
||||||
|
|
|
@ -98,7 +98,6 @@ const defaultProfile = {
|
||||||
formatRectangle,
|
formatRectangle,
|
||||||
filters,
|
filters,
|
||||||
|
|
||||||
journeysNumF: true, // `journeys()` method: support for `numF` field?
|
|
||||||
journeysOutFrwd: true, // `journeys()` method: support for `outFrwd` field?
|
journeysOutFrwd: true, // `journeys()` method: support for `outFrwd` field?
|
||||||
departuresGetPasslist: true, // `departures()` method: support for `getPasslist` field?
|
departuresGetPasslist: true, // `departures()` method: support for `getPasslist` field?
|
||||||
departuresStbFltrEquiv: true, // `departures()` method: support for `stbFltrEquiv` field?
|
departuresStbFltrEquiv: true, // `departures()` method: support for `stbFltrEquiv` field?
|
||||||
|
|
|
@ -71,7 +71,6 @@ const oebbProfile = {
|
||||||
parseLocation: parseHook(_parseLocation, fixWeirdPOIs),
|
parseLocation: parseHook(_parseLocation, fixWeirdPOIs),
|
||||||
parseMovement: parseHook(_parseMovement, fixMovement),
|
parseMovement: parseHook(_parseMovement, fixMovement),
|
||||||
|
|
||||||
journeysNumF: false,
|
|
||||||
trip: true,
|
trip: true,
|
||||||
radar: true,
|
radar: true,
|
||||||
reachableFrom: true
|
reachableFrom: true
|
||||||
|
|
|
@ -119,7 +119,6 @@ const vbbProfile = {
|
||||||
|
|
||||||
formatStation,
|
formatStation,
|
||||||
|
|
||||||
journeysNumF: true,
|
|
||||||
journeysWalkingSpeed: true,
|
journeysWalkingSpeed: true,
|
||||||
trip: true,
|
trip: true,
|
||||||
radar: true,
|
radar: true,
|
||||||
|
|
Loading…
Add table
Reference in a new issue