add support for brfares, discount decoding, other stuff

This commit is contained in:
eta 2023-01-14 12:19:02 +00:00
parent e06ba28b42
commit c946f48038
4 changed files with 1418 additions and 14 deletions

1337
rsp6-webshite/discounts.json Normal file

File diff suppressed because it is too large Load Diff

View File

@ -13,7 +13,7 @@
<div class="govuk-header__container govuk-width-container" style="border-bottom: 10px solid #1d70b8;"> <div class="govuk-header__container govuk-width-container" style="border-bottom: 10px solid #1d70b8;">
<div class="govuk-header__logo"> <div class="govuk-header__logo">
<a href="/" class="govuk-header__link govuk-header__link--homepage"> <a href="/" class="govuk-header__link govuk-header__link--homepage">
<span class="govuk-header__logotype-text">tickets™<small> by eta</small></span> <span class="govuk-header__logotype-text">rsp6-decoder</span>
</a> </a>
</div> </div>
</div> </div>
@ -145,8 +145,9 @@
<div class="govuk-footer__meta"> <div class="govuk-footer__meta">
<div class="govuk-footer__meta-item govuk-footer__meta-item--grow"> <div class="govuk-footer__meta-item govuk-footer__meta-item--grow">
<span class="govuk-footer__licence-description"> <span class="govuk-footer__licence-description">
Powered by <a class="govuk-footer__link" href="https://git.eta.st/eta/rsp6-decoder">rsp6-decoder (Rust)</a>, <a class="govuk-footer__link" href="https://git.eta.st/eta/rsp6-decoder">rsp6-decoder</a> version <span id="code-version" class="id-field">???</span>.
<a class="govuk-footer__link" href="https://github.com/zxing-js/library">zxing-js</a>, and Thanks to
<a class="govuk-footer__link" href="https://github.com/zxing-js/library">zxing-js</a> and
<a class="govuk-footer__link" href="https://github.com/rustwasm/wasm-bindgen">wasm-bindgen</a>. <a class="govuk-footer__link" href="https://github.com/rustwasm/wasm-bindgen">wasm-bindgen</a>.
Site design using the <a class="govuk-footer__link" href="https://github.com/alphagov/govuk-frontend">GOV.UK Design System</a>, under the terms of the <a class="govuk-footer__link" href="https://github.com/alphagov/govuk-frontend/blob/master/LICENSE.txt">MIT License</a>. Site design using the <a class="govuk-footer__link" href="https://github.com/alphagov/govuk-frontend">GOV.UK Design System</a>, under the terms of the <a class="govuk-footer__link" href="https://github.com/alphagov/govuk-frontend/blob/master/LICENSE.txt">MIT License</a>.
If you liked this, you might also enjoy <a class="govuk-footer__link" href="https://intertube.eta.st/">intertube</a>. If you liked this, you might also enjoy <a class="govuk-footer__link" href="https://intertube.eta.st/">intertube</a>.

View File

@ -1,16 +1,13 @@
// To do before release:
// - fix double scan bug
// - reservations!!
// - minification
console.log("[+] Wow, JavaScript!"); console.log("[+] Wow, JavaScript!");
import * as wasm from "rsp6-decoder"; import * as wasm from "rsp6-decoder";
import { BrowserAztecCodeReader } from '@zxing/library'; import { BrowserAztecCodeReader } from '@zxing/library';
let stations = require("./stations.json"); let stations = require("./stations.json");
let fares = require("./fares.json"); let fares = require("./fares.json");
let discounts = require("./discounts.json");
window.stations = stations; window.stations = stations;
window.fares = fares; window.fares = fares;
window.discounts = discounts;
let loaded = false; let loaded = false;
function onload() { function onload() {
@ -36,6 +33,7 @@ function onload() {
let file_upload = document.getElementById("file-upload-1"); let file_upload = document.getElementById("file-upload-1");
const codeReader = new BrowserAztecCodeReader(); const codeReader = new BrowserAztecCodeReader();
console.log("[+] Looks like everything initialised fine!"); console.log("[+] Looks like everything initialised fine!");
document.getElementById('code-version').innerHTML = __COMMIT_HASH__;
let selectedDeviceId; let selectedDeviceId;
@ -116,10 +114,42 @@ function onload() {
type = "Return (inbound)"; type = "Return (inbound)";
} }
else { else {
type = "<b>Season</b>"; type = "Season";
} }
if (data.bidirectional) {
type += " (bidirectional)";
}
let discount = null;
let discount_name = null;
if (data.discount_code) {
if (discounts[data.discount_code]) {
discount = discounts[data.discount_code].desc;
if (discounts[data.discount_code].code) {
discount_name = discounts[data.discount_code].code;
}
}
else {
discount = "Unknown discount (" + data.discount_code + ")";
}
}
let adult = data.child_ticket ? "Child" : "Adult";
let first = data.first_class ? "First Class" : "Standard Class";
document.getElementById("ticket-fromto").innerHTML = origin + " to " + destination; document.getElementById("ticket-fromto").innerHTML = origin + " to " + destination;
row("Fare", fare); if (data.manually_inspect) {
row("", "<i>Manual inspection required</i>");
}
let brfares_link = "https://www.brfares.com/!faredetail?orig=" + data.origin_nlc + "&dest=" + data.destination_nlc + "&tkt=" + data.fare;
if (data.route_code && data.route_code != 0) {
brfares_link += "&rte=" + data.route_code;
}
if (discount_name) {
brfares_link += "&rlc=" + discount_name;
}
row("Fare", fare + "<br/><small><a class=\"govuk-link\" href=\"" + brfares_link + "\">View on brfares.com</a></small>");
row("Class", adult + " " + first);
if (discount) {
row("Discount", discount);
}
row("Ticket type", type); row("Ticket type", type);
row("Start date", data.start_date); row("Start date", data.start_date);
if (data.depart_time_flag || data.depart_time != "00:00:00.0") { if (data.depart_time_flag || data.depart_time != "00:00:00.0") {
@ -144,6 +174,9 @@ function onload() {
} }
row("Valid for", dov + " day" + maybe_s); row("Valid for", dov + " day" + maybe_s);
} }
if (data.limited_duration) {
row("Limited duration", data.limited_duration);
}
row("Fare code", data.fare); row("Fare code", data.fare);
if (data.purchase_details) { if (data.purchase_details) {
let price = data.purchase_details.price_pence; let price = data.purchase_details.price_pence;
@ -153,6 +186,25 @@ function onload() {
row("Purchase reference", data.purchase_details.purchase_reference); row("Purchase reference", data.purchase_details.purchase_reference);
} }
} }
if (data.reservations.length > 0) {
let out = "";
data.reservations.forEach((resv) => {
if (out != "") {
out += "<br/>";
}
out += "<i>Train " + resv.retail_service_id + "</i></br>";
if (resv.coach == "*") {
out += "No specific seat";
}
else {
if (!resv.coach || resv.coach == " ") {
resv.coach = "?";
}
out += "Coach " + resv.coach + " Seat " + resv.seat_number + (resv.seat_letter ? resv.seat_letter : "");
}
});
row("Reservations", out);
}
let retailer = stations[data.retailer_id] ? stations[data.retailer_id].desc : "???"; let retailer = stations[data.retailer_id] ? stations[data.retailer_id].desc : "???";
row("Sold by", retailer + " (" + data.retailer_id + ")"); row("Sold by", retailer + " (" + data.retailer_id + ")");
if (data.route_code != 0) { if (data.route_code != 0) {
@ -162,7 +214,7 @@ function onload() {
row("Restriction", data.restriction_code); row("Restriction", data.restriction_code);
} }
if (data.discount_code != 0) { if (data.discount_code != 0) {
row("Discount code", data.route_code); row("Discount code", (discount_name ? discount_name + " / " : "") + data.discount_code);
} }
if (data.passenger_id) { if (data.passenger_id) {
row("Passenger ID", data.passenger_id); row("Passenger ID", data.passenger_id);
@ -191,15 +243,21 @@ function onload() {
error("Scanner failed", "Couldn't figure out what cameras you have on your device.<br/><pre>" + err + "</pre>"); error("Scanner failed", "Couldn't figure out what cameras you have on your device.<br/><pre>" + err + "</pre>");
}); });
let epoch = 0;
document.getElementById('scan-button').addEventListener('click', () => { document.getElementById('scan-button').addEventListener('click', () => {
let current_epoch = epoch + 1;
epoch = current_epoch;
decode_banner.style.display = "none"; decode_banner.style.display = "none";
ticket_content.style.display = "none"; ticket_content.style.display = "none";
codeReader.decodeFromInputVideoDevice(undefined, 'video').then((result) => { codeReader.decodeFromInputVideoDevice(undefined, 'video').then((result) => {
error_banner.style.display = "none"; error_banner.style.display = "none";
handleTicket(result); handleTicket(result);
}).catch((err) => { }).catch((err) => {
error("Scanner failed", "Looks like the barcode scanner failed in some way. If this keeps happening, try reloading the page or using one of the alternative options.<br/><pre>" + err + "</pre>"); if (epoch == current_epoch) {
console.error(err); error("Scanner failed", "Looks like the barcode scanner failed in some way. If this keeps happening, try reloading the page or using one of the alternative options.<br/><pre>" + err + "</pre>");
console.error(err);
}
}); });
video_div.style.display = "block"; video_div.style.display = "block";
console.log(`[+] Barcode scanner started on device ${selectedDeviceId}`); console.log(`[+] Barcode scanner started on device ${selectedDeviceId}`);

View File

@ -1,5 +1,10 @@
const CopyWebpackPlugin = require("copy-webpack-plugin"); const CopyWebpackPlugin = require("copy-webpack-plugin");
let commitHash = require('child_process')
.execSync('git rev-parse --short HEAD')
.toString()
.trim();
const path = require('path'); const path = require('path');
const webpack = require('webpack');
module.exports = { module.exports = {
entry: "./bootstrap.js", entry: "./bootstrap.js",
@ -9,6 +14,9 @@ module.exports = {
}, },
mode: "development", mode: "development",
plugins: [ plugins: [
new CopyWebpackPlugin(['index.html', 'govuk.css']) new CopyWebpackPlugin(['index.html', 'govuk.css']),
new webpack.DefinePlugin({
__COMMIT_HASH__: JSON.stringify(commitHash)
})
], ],
}; };