Commit 6c78c19a authored by Volker Krause's avatar Volker Krause
Browse files

Iterate over ERA SSB child nodes rather than PDF images

Avoid duplicating the ERA SSB decoding and prepares this for direct
barcode import.

As a welcome side-effect, anonymous passengers get saner numbers now.
parent 58274239
Pipeline #204616 passed with stage
in 2 minutes and 34 seconds
......@@ -4,7 +4,7 @@
SPDX-License-Identifier: LGPL-2.0-or-later
*/
function parsePdf(pdf) {
function parsePdf(pdf, node) {
var reservations = new Array();
for (var i = 0; i < pdf.pageCount; ++i) {
......@@ -33,27 +33,25 @@ function parsePdf(pdf) {
res.reservationFor.departureStation.name = dest[1];
res.reservationFor.arrivalStation.name = dest[2];
var images = page.images;
const barcodes = node.findChildNodes({ scope: "Descendants", mimeType: "internal/era-ssb", field: "issuerCode", match: "83" });
var offset = 0;
for (var j = 0; j < images.length; ++j) {
var barcode = Barcode.decodeAztecBinary(images[j]);
var barcodeB64 = barcode ? ByteArray.toBase64(barcode) : undefined;
if (!barcodeB64)
for (let j = 0; j < barcodes.length; ++j) {
if (barcodes[j].location != i) {
continue;
}
const ssb = barcodes[j].content;
var personalRes = JsonLd.clone(res);
personalRes.reservedTicket.ticketToken = "aztecbin:" + barcodeB64;
personalRes.reservedTicket.ticketToken = "aztecbin:" + ByteArray.toBase64(ssb.rawData);
var name = text.substr(offset).match(/(?:Passenger Name|Nome Passeggero(?:\/Passenger\n name)?).*\n(?: .*\n)* ?((?:\w+|\-\-).*?)(?: |\n)/);
offset += name.index + name[0].length;
if (name[1] !== "--") {
personalRes.underName.name = name[1];
} else {
personalRes.underName.name = "Passenger " + j;
personalRes.underName.name = "Passenger " + (j + 1);
}
// see https://community.kde.org/KDE_PIM/KItinerary/Trenitalia_Barcode
const ssb = Barcode.decodeEraSsbTicket(barcode)
personalRes.reservationFor.departureStation.identifier = "uic:" + (ssb.departureStationNum % 10000000)
if (ssb.departureStationNum != ssb.arrivalStationNum) {
personalRes.reservationFor.arrivalStation.identifier = "uic:" + (ssb.arrivalStationNum % 10000000)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment