File indexing completed on 2024-12-29 04:51:06
0001 /* 0002 SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org> 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 function parseEvent(event) { 0007 let res = JsonLd.newTrainReservation(); 0008 res.reservationFor.departureTime = JsonLd.readQDateTime(event, 'dtStart'); 0009 res.reservationFor.arrivalTime = JsonLd.readQDateTime(event, 'dtEnd'); 0010 res.reservationFor.departureStation.name = event.location; 0011 res.reservationFor.arrivalStation.name = event.summary.match(/.* → (.*) \[/)[1]; 0012 return res; 0013 } 0014 0015 function fixBrokenSncfTicketTokens(mail, node) 0016 { 0017 // fix JSON-LD in mail bodies containing messed up SNCF ticket tokens 0018 // and invalid train numbers 0019 const htmlNode = node.findChildNodes({ scope: "Children", mimeType: "text/html"})[0]; 0020 const pdfNodes = node.findChildNodes({ scope: "Children", mimeType: "application/pdf"}); 0021 if (pdfNodes.length == 0 || pdfNodes[0].result.length == 0 || htmlNode.result.length == 0) { 0022 return; 0023 } 0024 0025 let res = []; 0026 for (pdfNode of pdfNodes) { 0027 res = res.concat(pdfNode.result) 0028 } 0029 for (r of htmlNode.result) { 0030 if (r.reservedTicket.ticketToken.match(/^aztecCode:i0CV/i)) { 0031 r.reservedTicket.ticketToken = undefined; 0032 r.reservationFor.trainNumber = undefined; 0033 } 0034 // clear price information from HTML schema.org, as that's the trip total 0035 // while we get sub-prices from each PDF 0036 r.totalPrice = undefined; 0037 res.push(r); 0038 } 0039 return res; 0040 }