forked from ChelseaKR/tods-validate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
200 lines (190 loc) · 7.29 KB
/
Copy pathindex.html
File metadata and controls
200 lines (190 loc) · 7.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!--
Content-Security-Policy: restricts network access to the two origins
the playground actually needs: cdn.jsdelivr.net (Pyodide runtime, wasm,
and its bundled packages) and files.pythonhosted.org / pypi.org
(micropip fetching the tods-validate wheel and its metadata).
'wasm-unsafe-eval' is required for Pyodide's WebAssembly execution;
'unsafe-inline' is required for the inline <script> and <style> below.
-->
<meta
http-equiv="Content-Security-Policy"
content="default-src 'none'; script-src 'self' 'unsafe-inline' 'wasm-unsafe-eval' https://cdn.jsdelivr.net; style-src 'self' 'unsafe-inline'; connect-src https://cdn.jsdelivr.net https://files.pythonhosted.org https://pypi.org; img-src 'self' data:; frame-src 'self'; worker-src blob:; child-src blob:;"
/>
<title>tods-validate playground</title>
<style>
:root {
color-scheme: light dark;
--background: #ffffff;
--foreground: #111827;
--muted: #4b5563;
--border: #9ca3af;
}
@media (prefers-color-scheme: dark) {
:root {
--background: #111827;
--foreground: #f9fafb;
--muted: #d1d5db;
--border: #6b7280;
}
}
body {
font: 16px/1.5 system-ui, sans-serif;
max-width: 56rem;
margin: 2rem auto;
padding: 0 1rem;
color: var(--foreground);
background: var(--background);
}
h1 { margin-bottom: 0.25rem; }
.lede { color: var(--muted); margin-top: 0; }
.panel {
border: 1px solid var(--border);
border-radius: 8px;
padding: 1rem;
margin: 1rem 0;
}
button {
font: inherit;
padding: 0.5rem 1rem;
border-radius: 6px;
border: 1px solid #888;
cursor: pointer;
}
button:disabled { opacity: 0.65; cursor: progress; }
:focus-visible { outline: 3px solid currentColor; outline-offset: 3px; }
#status { color: var(--muted); }
iframe#report {
width: 100%;
min-height: 24rem;
border: 1px solid var(--border);
border-radius: 8px;
margin-top: 1rem;
}
code { background: rgba(127, 127, 127, 0.15); padding: 0 0.25rem; border-radius: 3px; }
</style>
</head>
<body>
<main>
<h1>tods-validate playground</h1>
<p class="lede">
Validate a Transit Operational Data Standard (TODS) feed in your browser.
Nothing is uploaded: the validator runs entirely on your machine via
Pyodide (WebAssembly), so it is safe for non-public operational data.
</p>
<div class="panel">
<p id="files-help">
Choose your TODS <code>.txt</code> files, and the companion GTFS files if
you have them (select them all together):
</p>
<label for="files"><strong>Feed files</strong></label>
<input type="file" id="files" aria-describedby="files-help" multiple />
<button id="run" disabled>Validate</button>
<p id="status" role="status">Loading Python (this takes a few seconds the first time)…</p>
</div>
<h2 id="report-heading" tabindex="-1">Validation report</h2>
<iframe
id="report"
title="Validation report"
sandbox="allow-same-origin"
srcdoc="<p>Validation results will appear here after you select feed files.</p>"
></iframe>
</main>
<footer>
<p id="footer-version"></p>
<p>
<a href="https://ko-fi.com/T6T6GMYTU" target="_blank" rel="noopener noreferrer"
>Support this work on Ko-fi</a
>
</p>
</footer>
<!-- Pyodide runtime. Update the version to the current Pyodide release,
and regenerate the integrity hash to match (SEC-20 / A11Y-17 note in
the standards audit): `curl -sSL <url> | openssl dgst -sha384 -binary
| openssl base64 -A`, prefixed with `sha384-`. -->
<script
src="https://cdn.jsdelivr.net/pyodide/v0.26.4/full/pyodide.js"
integrity="sha384-i3R37b3tF+HWudsUf1VSEOY2YxwSNMqY8DQa9Z0O3xh+NkJ9o+yjcGyIi5huj+nB"
crossorigin="anonymous"
></script>
<script>
// Keep in sync with the pinned wheel version below and the Pyodide
// <script> tag's src/integrity above when bumping either.
const TODS_VALIDATE_VERSION = "0.10.0";
const PYODIDE_VERSION = "v0.26.4";
const status = document.getElementById("status");
const runBtn = document.getElementById("run");
const filesInput = document.getElementById("files");
const report = document.getElementById("report");
const reportHeading = document.getElementById("report-heading");
const footerVersion = document.getElementById("footer-version");
const selected = new Map(); // filename -> Uint8Array
let pyodide;
footerVersion.textContent = `tods-validate ${TODS_VALIDATE_VERSION} · Pyodide ${PYODIDE_VERSION}`;
async function boot() {
pyodide = await loadPyodide();
await pyodide.loadPackage("micropip");
const micropip = pyodide.pyimport("micropip");
await micropip.install(`tods-validate==${TODS_VALIDATE_VERSION}`);
status.textContent = `Ready — validating with tods-validate ${TODS_VALIDATE_VERSION} on Pyodide ${PYODIDE_VERSION}. Choose your feed files, then click Validate.`;
runBtn.disabled = false;
}
filesInput.addEventListener("change", async (event) => {
selected.clear();
for (const file of event.target.files) {
selected.set(file.name, new Uint8Array(await file.arrayBuffer()));
}
status.textContent = `${selected.size} file(s) selected.`;
});
runBtn.addEventListener("click", async () => {
if (selected.size === 0) {
status.textContent = "Select your feed files first.";
return;
}
status.textContent = "Validating…";
try {
pyodide.FS.mkdir("/feed");
} catch (_) {
/* already exists from a previous run */
}
for (const [name, bytes] of selected) {
pyodide.FS.writeFile("/feed/" + name, bytes);
}
try {
const html = await pyodide.runPythonAsync(`
from tods_validate.api import validate_feed
from tods_validate.report import render_html
result = validate_feed("/feed")
render_html(result.findings, "your feed")
`);
report.srcdoc = html;
status.textContent = "Done.";
// Move focus to the report heading so keyboard/screen-reader users
// are taken to the newly rendered report.
reportHeading.focus();
} catch (err) {
status.textContent = "Validation error: " + err;
} finally {
for (const name of selected.keys()) {
try {
pyodide.FS.unlink("/feed/" + name);
} catch (_) {
/* ignore */
}
}
}
});
if (new URLSearchParams(window.location.search).has("a11y-static")) {
status.textContent = "Static accessibility audit mode.";
} else {
boot().catch((err) => {
status.textContent = "Failed to load Python: " + err;
});
}
</script>
</body>
</html>