Spaces:
Paused
Paused
Peng Ding commited on
Commit ·
4665394
1
Parent(s): 09a11ff
feat: add i18n dropdown, move badges to footer, add author credit
Browse files- Replace lang toggle button with <select> dropdown, auto-populated
from I18N dict keys — adding a language only requires a new dict entry
- Language preference persisted in localStorage
- Move shields.io badges from header to footer for cleaner header
- Add "Built by Oaklight · source on GitHub" footer line with i18n
- Remove HF Spaces badge (space taken down)
- Capacity ring gauge now has "Capacity" label
- src/veilrender/routes/dashboard.py +144 -32
src/veilrender/routes/dashboard.py
CHANGED
|
@@ -186,10 +186,22 @@ def _build_html() -> str:
|
|
| 186 |
color: var(--mint);
|
| 187 |
}}
|
| 188 |
.brand h1 span {{ color: var(--text); }}
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
.
|
| 192 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
|
| 194 |
/* Section label */
|
| 195 |
.sec {{
|
|
@@ -245,7 +257,11 @@ def _build_html() -> str:
|
|
| 245 |
}}
|
| 246 |
.ring-card {{
|
| 247 |
padding: 1.4rem;
|
| 248 |
-
display: flex; align-items: center; justify-content: center;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
}}
|
| 250 |
.ring-gauge {{ width: 120px; height: 120px; }}
|
| 251 |
.ring-num {{
|
|
@@ -295,11 +311,22 @@ def _build_html() -> str:
|
|
| 295 |
|
| 296 |
/* Footer */
|
| 297 |
.ftr {{
|
| 298 |
-
display: flex; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem;
|
| 299 |
font-size: 0.7rem; color: var(--text-3);
|
| 300 |
padding-top: 1.25rem;
|
| 301 |
border-top: 1px solid var(--border);
|
|
|
|
| 302 |
}}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
|
| 304 |
/* Responsive */
|
| 305 |
@media (max-width: 720px) {{
|
|
@@ -331,57 +358,56 @@ def _build_html() -> str:
|
|
| 331 |
<span class="ghost">👻</span>
|
| 332 |
<h1>Veil<span>Render</span></h1>
|
| 333 |
</div>
|
| 334 |
-
<
|
| 335 |
-
{_BADGES_HTML}
|
| 336 |
-
</div>
|
| 337 |
</div>
|
| 338 |
|
| 339 |
-
<div class="sec in d1">Status</div>
|
| 340 |
<div class="status in d2">
|
| 341 |
<div class="card">
|
| 342 |
<span class="dot {dot_cls}" id="dot"></span>
|
| 343 |
-
<span class="s-label">Browser</span>
|
| 344 |
-
<span class="s-val" id="browser-val">{browser_label}</span>
|
| 345 |
</div>
|
| 346 |
<div class="card">
|
| 347 |
-
<span class="s-label">Uptime</span>
|
| 348 |
<span class="s-val" id="uptime-val">{stats.format_uptime()}</span>
|
| 349 |
</div>
|
| 350 |
</div>
|
| 351 |
|
| 352 |
-
<div class="sec in d2">Metrics</div>
|
| 353 |
<div class="metrics in d3">
|
| 354 |
<div class="card ring-card">
|
| 355 |
{ring_svg}
|
|
|
|
| 356 |
</div>
|
| 357 |
<div class="nums">
|
| 358 |
<div class="card num">
|
| 359 |
-
<div class="lbl">Requests</div>
|
| 360 |
<div class="val c-mint" id="total-req">{total_req}</div>
|
| 361 |
</div>
|
| 362 |
<div class="card num">
|
| 363 |
-
<div class="lbl">Successes</div>
|
| 364 |
<div class="val c-ok" id="total-ok">{total_ok}</div>
|
| 365 |
</div>
|
| 366 |
<div class="card num">
|
| 367 |
-
<div class="lbl">Failures</div>
|
| 368 |
<div class="val {"c-err" if total_fail > 0 else "c-ok"}" id="total-fail">{total_fail}</div>
|
| 369 |
</div>
|
| 370 |
</div>
|
| 371 |
</div>
|
| 372 |
|
| 373 |
-
<div class="sec in d3">Endpoints</div>
|
| 374 |
<div class="card tbl in d4">
|
| 375 |
<table>
|
| 376 |
<thead>
|
| 377 |
<tr>
|
| 378 |
-
<th>Endpoint</th>
|
| 379 |
-
<th>Requests</th>
|
| 380 |
-
<th>Success</th>
|
| 381 |
-
<th>Failure</th>
|
| 382 |
-
<th>Rate</th>
|
| 383 |
-
<th>Avg Latency</th>
|
| 384 |
-
<th>P95 Latency</th>
|
| 385 |
</tr>
|
| 386 |
</thead>
|
| 387 |
<tbody>
|
|
@@ -392,26 +418,114 @@ def _build_html() -> str:
|
|
| 392 |
</div>
|
| 393 |
|
| 394 |
<div class="ftr in d4">
|
| 395 |
-
<
|
| 396 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 397 |
</div>
|
| 398 |
|
| 399 |
</div>
|
| 400 |
<script>
|
| 401 |
(function() {{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 402 |
var CIRC = 2 * Math.PI * 40;
|
| 403 |
function rateClass(r) {{ return r >= 95 ? 'c-ok' : r >= 80 ? 'c-warn' : 'c-err'; }}
|
| 404 |
function ringColor(u) {{ return u < 70 ? '#6ee7b7' : u < 90 ? '#fbbf24' : '#f87171'; }}
|
| 405 |
|
| 406 |
function update() {{
|
| 407 |
fetch('/stats').then(function(r) {{ return r.json(); }}).then(function(d) {{
|
| 408 |
-
|
|
|
|
| 409 |
var dot = document.getElementById('dot');
|
| 410 |
dot.className = 'dot ' + (d.browser_alive ? 'dot-on' : 'dot-off');
|
| 411 |
-
document.getElementById('browser-val').textContent = d.browser_alive ?
|
| 412 |
document.getElementById('uptime-val').textContent = d.uptime;
|
| 413 |
|
| 414 |
-
// Ring gauge
|
| 415 |
var u = d.utilization;
|
| 416 |
var filled = CIRC * u / 100;
|
| 417 |
var gap = CIRC - filled;
|
|
@@ -423,14 +537,12 @@ def _build_html() -> str:
|
|
| 423 |
document.getElementById('ring-active').textContent = d.active;
|
| 424 |
document.getElementById('ring-max').textContent = '/ ' + d.max_concurrent;
|
| 425 |
|
| 426 |
-
// Totals
|
| 427 |
document.getElementById('total-req').textContent = d.total_requests;
|
| 428 |
document.getElementById('total-ok').textContent = d.total_successes;
|
| 429 |
var failEl = document.getElementById('total-fail');
|
| 430 |
failEl.textContent = d.total_failures;
|
| 431 |
failEl.className = 'val ' + (d.total_failures > 0 ? 'c-err' : 'c-ok');
|
| 432 |
|
| 433 |
-
// Endpoint rows
|
| 434 |
var eps = d.endpoints;
|
| 435 |
for (var name in eps) {{
|
| 436 |
var e = eps[name];
|
|
|
|
| 186 |
color: var(--mint);
|
| 187 |
}}
|
| 188 |
.brand h1 span {{ color: var(--text); }}
|
| 189 |
+
|
| 190 |
+
/* Lang select */
|
| 191 |
+
.lang-sel {{
|
| 192 |
+
font-family: var(--ff); font-size: 0.7rem; font-weight: 500;
|
| 193 |
+
background: var(--surface); color: var(--text-2);
|
| 194 |
+
border: 1px solid var(--border); border-radius: 6px;
|
| 195 |
+
padding: 0.3rem 0.5rem; cursor: pointer;
|
| 196 |
+
transition: border-color 0.2s, color 0.2s;
|
| 197 |
+
-webkit-appearance: none; appearance: none;
|
| 198 |
+
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%234a6650'/%3E%3C/svg%3E");
|
| 199 |
+
background-repeat: no-repeat;
|
| 200 |
+
background-position: right 0.4rem center;
|
| 201 |
+
padding-right: 1.3rem;
|
| 202 |
+
}}
|
| 203 |
+
.lang-sel:hover {{ border-color: var(--border-hi); color: var(--text); }}
|
| 204 |
+
.lang-sel option {{ background: var(--surface); color: var(--text); }}
|
| 205 |
|
| 206 |
/* Section label */
|
| 207 |
.sec {{
|
|
|
|
| 257 |
}}
|
| 258 |
.ring-card {{
|
| 259 |
padding: 1.4rem;
|
| 260 |
+
display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.5rem;
|
| 261 |
+
}}
|
| 262 |
+
.ring-lbl {{
|
| 263 |
+
font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.06em;
|
| 264 |
+
color: var(--text-2);
|
| 265 |
}}
|
| 266 |
.ring-gauge {{ width: 120px; height: 120px; }}
|
| 267 |
.ring-num {{
|
|
|
|
| 311 |
|
| 312 |
/* Footer */
|
| 313 |
.ftr {{
|
|
|
|
| 314 |
font-size: 0.7rem; color: var(--text-3);
|
| 315 |
padding-top: 1.25rem;
|
| 316 |
border-top: 1px solid var(--border);
|
| 317 |
+
display: flex; flex-direction: column; gap: 0.75rem;
|
| 318 |
}}
|
| 319 |
+
.ftr a {{ color: var(--mint-dim); text-decoration: none; }}
|
| 320 |
+
.ftr a:hover {{ color: var(--mint); }}
|
| 321 |
+
.ftr-row {{
|
| 322 |
+
display: flex; justify-content: space-between; flex-wrap: wrap; gap: 0.5rem;
|
| 323 |
+
}}
|
| 324 |
+
.ftr-badges {{
|
| 325 |
+
display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center;
|
| 326 |
+
}}
|
| 327 |
+
.ftr-badges a {{ opacity: 0.6; transition: opacity 0.2s; }}
|
| 328 |
+
.ftr-badges a:hover {{ opacity: 1; }}
|
| 329 |
+
.ftr-badges img {{ height: 18px; vertical-align: middle; }}
|
| 330 |
|
| 331 |
/* Responsive */
|
| 332 |
@media (max-width: 720px) {{
|
|
|
|
| 358 |
<span class="ghost">👻</span>
|
| 359 |
<h1>Veil<span>Render</span></h1>
|
| 360 |
</div>
|
| 361 |
+
<select class="lang-sel" id="lang-sel" onchange="setLang(this.value)"></select>
|
|
|
|
|
|
|
| 362 |
</div>
|
| 363 |
|
| 364 |
+
<div class="sec in d1" data-i18n="sec_status">Status</div>
|
| 365 |
<div class="status in d2">
|
| 366 |
<div class="card">
|
| 367 |
<span class="dot {dot_cls}" id="dot"></span>
|
| 368 |
+
<span class="s-label" data-i18n="browser">Browser</span>
|
| 369 |
+
<span class="s-val" id="browser-val" data-i18n-key="browser_status">{browser_label}</span>
|
| 370 |
</div>
|
| 371 |
<div class="card">
|
| 372 |
+
<span class="s-label" data-i18n="uptime">Uptime</span>
|
| 373 |
<span class="s-val" id="uptime-val">{stats.format_uptime()}</span>
|
| 374 |
</div>
|
| 375 |
</div>
|
| 376 |
|
| 377 |
+
<div class="sec in d2" data-i18n="sec_metrics">Metrics</div>
|
| 378 |
<div class="metrics in d3">
|
| 379 |
<div class="card ring-card">
|
| 380 |
{ring_svg}
|
| 381 |
+
<div class="ring-lbl" data-i18n="capacity">Capacity</div>
|
| 382 |
</div>
|
| 383 |
<div class="nums">
|
| 384 |
<div class="card num">
|
| 385 |
+
<div class="lbl" data-i18n="requests">Requests</div>
|
| 386 |
<div class="val c-mint" id="total-req">{total_req}</div>
|
| 387 |
</div>
|
| 388 |
<div class="card num">
|
| 389 |
+
<div class="lbl" data-i18n="successes">Successes</div>
|
| 390 |
<div class="val c-ok" id="total-ok">{total_ok}</div>
|
| 391 |
</div>
|
| 392 |
<div class="card num">
|
| 393 |
+
<div class="lbl" data-i18n="failures">Failures</div>
|
| 394 |
<div class="val {"c-err" if total_fail > 0 else "c-ok"}" id="total-fail">{total_fail}</div>
|
| 395 |
</div>
|
| 396 |
</div>
|
| 397 |
</div>
|
| 398 |
|
| 399 |
+
<div class="sec in d3" data-i18n="sec_endpoints">Endpoints</div>
|
| 400 |
<div class="card tbl in d4">
|
| 401 |
<table>
|
| 402 |
<thead>
|
| 403 |
<tr>
|
| 404 |
+
<th data-i18n="th_endpoint">Endpoint</th>
|
| 405 |
+
<th data-i18n="th_requests">Requests</th>
|
| 406 |
+
<th data-i18n="th_success">Success</th>
|
| 407 |
+
<th data-i18n="th_failure">Failure</th>
|
| 408 |
+
<th data-i18n="th_rate">Rate</th>
|
| 409 |
+
<th data-i18n="th_avg">Avg Latency</th>
|
| 410 |
+
<th data-i18n="th_p95">P95 Latency</th>
|
| 411 |
</tr>
|
| 412 |
</thead>
|
| 413 |
<tbody>
|
|
|
|
| 418 |
</div>
|
| 419 |
|
| 420 |
<div class="ftr in d4">
|
| 421 |
+
<div class="ftr-row">
|
| 422 |
+
<span data-i18n="footer_info">Live updates every 5 s · stats are in-memory, reset on restart</span>
|
| 423 |
+
<span data-i18n="footer_author">Built by <a href="https://github.com/Oaklight">Oaklight</a> · <a href="https://github.com/Oaklight/veilrender">source on GitHub</a></span>
|
| 424 |
+
</div>
|
| 425 |
+
<div class="ftr-badges">
|
| 426 |
+
{_BADGES_HTML}
|
| 427 |
+
</div>
|
| 428 |
</div>
|
| 429 |
|
| 430 |
</div>
|
| 431 |
<script>
|
| 432 |
(function() {{
|
| 433 |
+
/* ——— i18n ——— */
|
| 434 |
+
var I18N = {{
|
| 435 |
+
en: {{
|
| 436 |
+
_label: 'English',
|
| 437 |
+
sec_status: 'Status',
|
| 438 |
+
sec_metrics: 'Metrics',
|
| 439 |
+
sec_endpoints: 'Endpoints',
|
| 440 |
+
browser: 'Browser',
|
| 441 |
+
uptime: 'Uptime',
|
| 442 |
+
capacity: 'Capacity',
|
| 443 |
+
requests: 'Requests',
|
| 444 |
+
successes: 'Successes',
|
| 445 |
+
failures: 'Failures',
|
| 446 |
+
th_endpoint: 'Endpoint',
|
| 447 |
+
th_requests: 'Requests',
|
| 448 |
+
th_success: 'Success',
|
| 449 |
+
th_failure: 'Failure',
|
| 450 |
+
th_rate: 'Rate',
|
| 451 |
+
th_avg: 'Avg Latency',
|
| 452 |
+
th_p95: 'P95 Latency',
|
| 453 |
+
footer_info: 'Live updates every 5 s · stats are in-memory, reset on restart',
|
| 454 |
+
footer_author: 'Built by Oaklight · source on GitHub',
|
| 455 |
+
alive: 'alive',
|
| 456 |
+
dead: 'dead'
|
| 457 |
+
}},
|
| 458 |
+
zh: {{
|
| 459 |
+
_label: '中文',
|
| 460 |
+
sec_status: '状态',
|
| 461 |
+
sec_metrics: '指标',
|
| 462 |
+
sec_endpoints: '接口',
|
| 463 |
+
browser: '浏览器',
|
| 464 |
+
uptime: '运行时间',
|
| 465 |
+
capacity: '容量',
|
| 466 |
+
requests: '请求数',
|
| 467 |
+
successes: '成功',
|
| 468 |
+
failures: '失败',
|
| 469 |
+
th_endpoint: '接口',
|
| 470 |
+
th_requests: '请求',
|
| 471 |
+
th_success: '成功',
|
| 472 |
+
th_failure: '失败',
|
| 473 |
+
th_rate: '成功率',
|
| 474 |
+
th_avg: '平均延迟',
|
| 475 |
+
th_p95: 'P95 延迟',
|
| 476 |
+
footer_info: '每 5 秒自动更新 · 统计数据存储在内存中,重启后重置',
|
| 477 |
+
footer_author: '由 Oaklight 构建 · 源码见 GitHub',
|
| 478 |
+
alive: '运行中',
|
| 479 |
+
dead: '已停止'
|
| 480 |
+
}}
|
| 481 |
+
}};
|
| 482 |
+
|
| 483 |
+
var lang = localStorage.getItem('vr_lang') || 'en';
|
| 484 |
+
var sel = document.getElementById('lang-sel');
|
| 485 |
+
|
| 486 |
+
// Populate select options from I18N keys
|
| 487 |
+
Object.keys(I18N).forEach(function(k) {{
|
| 488 |
+
var opt = document.createElement('option');
|
| 489 |
+
opt.value = k;
|
| 490 |
+
opt.textContent = I18N[k]._label;
|
| 491 |
+
sel.appendChild(opt);
|
| 492 |
+
}});
|
| 493 |
+
|
| 494 |
+
function applyLang(l) {{
|
| 495 |
+
lang = l;
|
| 496 |
+
localStorage.setItem('vr_lang', l);
|
| 497 |
+
sel.value = l;
|
| 498 |
+
var t = I18N[l];
|
| 499 |
+
document.querySelectorAll('[data-i18n]').forEach(function(el) {{
|
| 500 |
+
var key = el.getAttribute('data-i18n');
|
| 501 |
+
if (t[key] != null) el.textContent = t[key];
|
| 502 |
+
}});
|
| 503 |
+
var bv = document.getElementById('browser-val');
|
| 504 |
+
if (bv.getAttribute('data-i18n-key') === 'browser_status') {{
|
| 505 |
+
var alive = document.getElementById('dot').classList.contains('dot-on');
|
| 506 |
+
bv.textContent = alive ? t.alive : t.dead;
|
| 507 |
+
}}
|
| 508 |
+
document.documentElement.lang = l;
|
| 509 |
+
}}
|
| 510 |
+
|
| 511 |
+
window.setLang = function(l) {{ applyLang(l); }};
|
| 512 |
+
|
| 513 |
+
applyLang(lang);
|
| 514 |
+
|
| 515 |
+
/* ——— Live data polling ——— */
|
| 516 |
var CIRC = 2 * Math.PI * 40;
|
| 517 |
function rateClass(r) {{ return r >= 95 ? 'c-ok' : r >= 80 ? 'c-warn' : 'c-err'; }}
|
| 518 |
function ringColor(u) {{ return u < 70 ? '#6ee7b7' : u < 90 ? '#fbbf24' : '#f87171'; }}
|
| 519 |
|
| 520 |
function update() {{
|
| 521 |
fetch('/stats').then(function(r) {{ return r.json(); }}).then(function(d) {{
|
| 522 |
+
var t = I18N[lang];
|
| 523 |
+
|
| 524 |
var dot = document.getElementById('dot');
|
| 525 |
dot.className = 'dot ' + (d.browser_alive ? 'dot-on' : 'dot-off');
|
| 526 |
+
document.getElementById('browser-val').textContent = d.browser_alive ? t.alive : t.dead;
|
| 527 |
document.getElementById('uptime-val').textContent = d.uptime;
|
| 528 |
|
|
|
|
| 529 |
var u = d.utilization;
|
| 530 |
var filled = CIRC * u / 100;
|
| 531 |
var gap = CIRC - filled;
|
|
|
|
| 537 |
document.getElementById('ring-active').textContent = d.active;
|
| 538 |
document.getElementById('ring-max').textContent = '/ ' + d.max_concurrent;
|
| 539 |
|
|
|
|
| 540 |
document.getElementById('total-req').textContent = d.total_requests;
|
| 541 |
document.getElementById('total-ok').textContent = d.total_successes;
|
| 542 |
var failEl = document.getElementById('total-fail');
|
| 543 |
failEl.textContent = d.total_failures;
|
| 544 |
failEl.className = 'val ' + (d.total_failures > 0 ? 'c-err' : 'c-ok');
|
| 545 |
|
|
|
|
| 546 |
var eps = d.endpoints;
|
| 547 |
for (var name in eps) {{
|
| 548 |
var e = eps[name];
|