mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-22 22:59:35 +02:00
DB: optionally parse ticket URLs
Co-Authored-By: Jannis R <mail@jannisr.de>
This commit is contained in:
parent
784d273adf
commit
c4966aeca7
1 changed files with 54 additions and 0 deletions
|
@ -260,6 +260,55 @@ const formatRefreshJourneyReq = (ctx, refreshToken) => {
|
|||
};
|
||||
};
|
||||
|
||||
const parseShpCtx = (addDataTicketInfo) => {
|
||||
try {
|
||||
return JSON.parse(atob(addDataTicketInfo)).shpCtx;
|
||||
} catch (e) {
|
||||
// in case addDataTicketInfo is not a valid base64 string
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
const addDbOfferSelectionUrl = (journey, opt) => {
|
||||
|
||||
// if no ticket contains addData, we can't get the offer selection URL
|
||||
if (journey.tickets.some((t) => t.addDataTicketInfo)) {
|
||||
|
||||
const queryParams = new URLSearchParams();
|
||||
|
||||
// Add individual parameters
|
||||
queryParams.append('A.1', opt.age);
|
||||
queryParams.append('E', 'F');
|
||||
queryParams.append('E.1', opt.loyaltyCard ? formatLoyaltyCard(opt.loyaltyCard) : '0');
|
||||
queryParams.append('K', opt.firstClass ? '1' : '2');
|
||||
queryParams.append('M', 'D');
|
||||
queryParams.append('RT.1', 'E');
|
||||
queryParams.append('SS', journey.legs[0].origin.id);
|
||||
queryParams.append('T', journey.legs[0].departure);
|
||||
queryParams.append('VH', journey.refreshToken);
|
||||
queryParams.append('ZS', journey.legs[journey.legs.length - 1].destination.id);
|
||||
queryParams.append('journeyOptions', '0');
|
||||
queryParams.append('journeyProducts', '1023');
|
||||
queryParams.append('optimize', '1');
|
||||
queryParams.append('returnurl', 'dbnavigator://');
|
||||
const endpoint = opt.language === 'de' ? 'dox' : 'eox';
|
||||
|
||||
journey.tickets.forEach((t) => {
|
||||
const shpCtx = parseShpCtx(t.addDataTicketInfo);
|
||||
if (shpCtx) {
|
||||
const url = new URL(`https://mobile.bahn.de/bin/mobil/query.exe/${endpoint}`);
|
||||
url.searchParams = new URLSearchParams(queryParams);
|
||||
url.searchParams.append('shpCtx', shpCtx);
|
||||
t.url = url.href;
|
||||
} else {
|
||||
t.url = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// todo: fix this
|
||||
// line: {
|
||||
// type: 'line',
|
||||
|
@ -357,6 +406,10 @@ const mutateToAddTickets = (parsed, opt, j) => {
|
|||
currency: 'EUR',
|
||||
};
|
||||
}
|
||||
if (opt.generateUnreliableTicketUrls) {
|
||||
addDbOfferSelectionUrl(parsed, opt);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -635,6 +688,7 @@ const profile = {
|
|||
|
||||
formatStation,
|
||||
|
||||
generateUnreliableTicketUrls: false,
|
||||
refreshJourneyUseOutReconL: true,
|
||||
trip: true,
|
||||
journeysFromTrip: true,
|
||||
|
|
Loading…
Add table
Reference in a new issue