From 6ff406ea79d3891bcd0dfbfc2b510fb9c06c50ba Mon Sep 17 00:00:00 2001 From: Traines Date: Thu, 13 Feb 2025 20:09:18 +0000 Subject: [PATCH] artificially filter for includeRelatedStations and direction --- api.js | 8 ++++---- index.js | 8 +++++++- p/dbweb/station-board-req.js | 2 +- parse/arrival-or-departure.js | 2 +- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/api.js b/api.js index 308aba00..defc97fd 100644 --- a/api.js +++ b/api.js @@ -47,10 +47,10 @@ const config = { }; const profiles = { - 'db': dbProfile, - 'dbnav': dbnavProfile, - 'dbweb': dbwebProfile -} + db: dbProfile, + dbnav: dbnavProfile, + dbweb: dbwebProfile, +}; const start = async () => { const vendo = createClient( diff --git a/index.js b/index.js index ee787c2e..0b78d520 100644 --- a/index.js +++ b/index.js @@ -106,9 +106,15 @@ const createClient = (profile, userAgent, opt = {}) => { const {res} = await profile.request({profile, opt}, userAgent, req); const ctx = {profile, opt, common, res}; - const results = (res[resultsField] || res.items || res.bahnhofstafelAbfahrtPositionen || res.bahnhofstafelAnkunftPositionen || res.entries) + let results = (res[resultsField] || res.items || res.bahnhofstafelAbfahrtPositionen || res.bahnhofstafelAnkunftPositionen || res.entries) .map(res => parse(ctx, res)); // TODO sort?, slice + if (!opt.includeRelatedStations) { + results = results.filter(r => !r.stop?.id || r.stop.id == station); + } + if (opt.direction) { + results = results.filter(r => !r.nextStopovers || r.nextStopovers.find(s => s.stop?.id == opt.direction || s.stop?.name == opt.direction)); + } return { [resultsField]: results, realtimeDataUpdatedAt: null, // TODO diff --git a/p/dbweb/station-board-req.js b/p/dbweb/station-board-req.js index 7a8c3101..7196e62b 100644 --- a/p/dbweb/station-board-req.js +++ b/p/dbweb/station-board-req.js @@ -8,7 +8,7 @@ const formatStationBoardReq = (ctx, station, type) => { ortExtId: station, zeit: profile.formatTimeOfDay(profile, opt.when), datum: profile.formatDate(profile, opt.when), - mitVias: opt.stopovers || undefined, + mitVias: opt.stopovers || Boolean(opt.direction) || undefined, verkehrsmittel: profile.formatProductsFilter(ctx, opt.products || {}), }, method: 'GET', diff --git a/parse/arrival-or-departure.js b/parse/arrival-or-departure.js index 9259a105..2dab416c 100644 --- a/parse/arrival-or-departure.js +++ b/parse/arrival-or-departure.js @@ -40,7 +40,7 @@ const createParseArrOrDep = (prefix) => { res.remarks = profile.parseRemarks(ctx, d); } - if (opt.stopovers && Array.isArray(d.ueber)) { + if ((opt.stopovers || opt.direction) && Array.isArray(d.ueber)) { const stopovers = d.ueber .map(viaName => profile.parseStopover(ctx, {name: viaName}, null));