Skip to content

Commit

Permalink
DB: fix parsing of ticket URLs 🐛
Browse files Browse the repository at this point in the history
URL.prototype.searchParams is read-only, so we just mutate it.

follow-up of c4966ae
  • Loading branch information
derhuerst committed Dec 10, 2024
1 parent e9211e8 commit 75de610
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions p/db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -261,32 +261,29 @@ 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('A.1', opt.age);
url.searchParams.append('E', 'F');
url.searchParams.append('E.1', opt.loyaltyCard ? formatLoyaltyCard(opt.loyaltyCard) : '0');
url.searchParams.append('K', opt.firstClass ? '1' : '2');
url.searchParams.append('M', 'D');
url.searchParams.append('RT.1', 'E');
url.searchParams.append('SS', journey.legs[0].origin.id);
url.searchParams.append('T', journey.legs[0].departure);
url.searchParams.append('VH', journey.refreshToken);
url.searchParams.append('ZS', journey.legs[journey.legs.length - 1].destination.id);
url.searchParams.append('journeyOptions', '0');
url.searchParams.append('journeyProducts', '1023');
url.searchParams.append('optimize', '1');
url.searchParams.append('returnurl', 'dbnavigator://');
url.searchParams.append('shpCtx', shpCtx);

t.url = url.href;
} else {
t.url = null;
Expand Down

0 comments on commit 75de610

Please sign in to comment.