Commit c06e62cd authored by Volker Krause's avatar Volker Krause
Browse files

Export binary content document nodes as JS ArrayBuffer objects directly

This removes the need for explicit conversion and some other hacks to work
around the lack of access to opaque QByteArray variants.
parent 0ae527ce
Pipeline #76079 passed with stage
in 13 minutes and 31 seconds
......@@ -62,7 +62,7 @@ QString JsApi::ByteArray::decodeUtf8(const QByteArray &input) const
QString JsApi::ByteArray::decodeLatin1(const QByteArray &input) const
{
return QString::fromLatin1(input.constData(), input.size());
return QString::fromLatin1(input);
}
QVariant JsApi::ByteArray::toBitArray(const QByteArray &input) const
......
......@@ -8,6 +8,11 @@
#include <KItinerary/ExtractorFilter>
#include <QQmlEngine>
#include <private/qv4arraybuffer_p.h>
#include <private/qv4engine_p.h>
using namespace KItinerary;
ExtractorDocumentNode BinaryDocumentProcessor::createNodeFromData(const QByteArray &encodedData) const
......@@ -21,3 +26,8 @@ bool BinaryDocumentProcessor::matches(const ExtractorFilter &filter, const Extra
{
return filter.matches(QString::fromLatin1(node.content<QByteArray>()));
}
QJSValue BinaryDocumentProcessor::contentToScriptValue(const ExtractorDocumentNode &node, QJSEngine *engine) const
{
return QJSValue(engine->handle(), engine->handle()->newArrayBuffer(node.content<QByteArray>())->asReturnedValue());
}
......@@ -16,6 +16,7 @@ class BinaryDocumentProcessor : public ExtractorDocumentProcessor
public:
ExtractorDocumentNode createNodeFromData(const QByteArray &encodedData) const override;
bool matches(const ExtractorFilter &filter, const ExtractorDocumentNode &node) const override;
QJSValue contentToScriptValue(const ExtractorDocumentNode &node, QJSEngine *engine) const override;
};
}
......
......@@ -23,8 +23,7 @@ function parseTicket(pdf, node, triggerNode) {
res.reservedTicket.ticketToken = "pdf417bin:" + ByteArray.toBase64(triggerNode.content);
// see https://community.kde.org/KDE_PIM/KItinerary/MAV_Barcode
const outer = ByteArray.toArrayBuffer(triggerNode.content);
const inner = ByteArray.inflate(outer.slice(2));
const inner = ByteArray.inflate(triggerNode.content.slice(2));
if (inner.byteLength >= 217) {
const view = new DataView(inner);
res.reservationFor.departureStation.identifier = "uic:" + (view.getUint32(106, false) & 0xffffff);
......
......@@ -234,17 +234,17 @@ function parseSecutixPdf(pdf, node, triggerNode)
{
// see https://community.kde.org/KDE_PIM/KItinerary/SNCF_Barcodes#SNCF_Secutix_Tickets
var res = JsonLd.newTrainReservation();
var code = ByteArray.decodeLatin1(triggerNode.content);
res.reservationNumber = code.substr(268, 9);
res.reservationFor.departureStation.name = code.substr(277, 5);
res.reservationFor.departureStation.identifier = "sncf:" + code.substr(277, 5);
res.reservationFor.arrivalStation.name = code.substr(282, 5);
res.reservationFor.arrivalStation.identifier = "sncf:" + code.substr(282, 5);
res.reservationFor.departureDay = JsonLd.toDateTime(code.substr(343, 8), "ddMMyyyy", "fr");
res.reservedTicket.ticketedSeat.seatingType = code.substr(351, 1);
var code = ByteArray.decodeLatin1(triggerNode.content.slice(260));
res.reservationNumber = code.substr(8, 9);
res.reservationFor.departureStation.name = code.substr(17, 5);
res.reservationFor.departureStation.identifier = "sncf:" + code.substr(17, 5);
res.reservationFor.arrivalStation.name = code.substr(22, 5);
res.reservationFor.arrivalStation.identifier = "sncf:" + code.substr(22, 5);
res.reservationFor.departureDay = JsonLd.toDateTime(code.substr(83, 8), "ddMMyyyy", "fr");
res.reservedTicket.ticketedSeat.seatingType = code.substr(91, 1);
res.reservedTicket.ticketToken = "aztecbin:" + ByteArray.toBase64(triggerNode.content);
res.underName.familyName = code.substr(376, 19);
res.underName.givenName = code.substr(395, 19);
res.underName.familyName = code.substr(116, 19);
res.underName.givenName = code.substr(135, 19);
var text = pdf.pages[triggerNode.location].text;
var pnr = text.match(res.reservationNumber + '[^\n]* ([A-Z0-9]{6})\n');
......
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