Dawnline 0.14.0
Build packages / CI (push) Blocked by required conditions
Build packages / Version (push) Waiting to run
CI / Web (format, types, tests, bundles) (push) Blocked by required conditions
CI / ShellCheck (push) Blocked by required conditions
CI / ucode static checks (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 24.10) (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 25.12) (push) Blocked by required conditions
Build packages / CI (push) Blocked by required conditions
Build packages / Version (push) Waiting to run
CI / Web (format, types, tests, bundles) (push) Blocked by required conditions
CI / ShellCheck (push) Blocked by required conditions
CI / ucode static checks (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 24.10) (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 25.12) (push) Blocked by required conditions
- A device is renamed where its name stands on its card: a click on the
name, Return or Space on it, or Rename in the ⋯ menu turns it into a
field with the name selected. Return saves, and the words shimmer until
the router answers. Esc or a click elsewhere puts the old name back. The
rename window is gone, and the page no longer redraws under a name being
edited
- Device names take up to 20 characters: letters of any language, digits,
spaces and - _ . The router refuses anything else when a device is added
or renamed, so a name can't carry symbols into configurations, file
names or the AmneziaVPN key. The portal and the admin turn a character
like that away as it is typed: the field shakes, its outline goes red
and a short line says why. Suggested names (a phone's model, "Phone 2")
are stripped of such characters and cut to fit. Names set before this
stay as they are
- LAN Bypass: Add a device, in the portal and in the admin, has a switch
that keeps the device's own local network (printer, TV, NAS) reachable
while it is connected. It is off by default and stays as chosen; the
admin's device drawer shows it. With home and internet access the switch
says which addresses still lead to the home network
- Health warns when a server's home network is on one of the subnets home
routers come with (192.168.0.x, 192.168.1.x and others). People with
home access who connect from a network on the same addresses reach your
home instead of their own, LAN Bypass or not
- The router tells when a device can't connect properly. After the problem
lasts three minutes, the portal card and the admin drawer name it:
can't finish connecting (the network may block it), connected but no
data (an outdated configuration, and the card offers Reconnect), on two
devices at once, or a connection that keeps dropping. Activity lists
these under Problems, one line per device per hour, and says when the
device connects normally again
- The set-up sheet's connection line follows what the device does:
waiting, can't finish, connected, or connected but no data. The sheet
closes by itself only once data comes through. On the device itself and
for a router, the steps regroup to what fixes the problem: "Set it up
again" when the handshake never finishes, "Add the connection again"
("Import the configuration again" for a router) when no data comes
- Set-up in the portal: a QR code too long for a camera to read gives its
place to a code that opens the set-up link (a LAN Bypass configuration
or a long AmneziaVPN key can be that long). A TV, box or NAS added from
a phone gets the steps for setting up from another device. Back from
"Open on the device" keeps the kind, LAN Bypass and the name typed. The
packet-size note under the kinds is gone
- The portal on phones keeps its place: nothing jumps when an access row
opens or folds, a notice comes or goes, or Safari redraws the cards. A
reload, or coming back from the VPN app, opens where the page was. Cards
glide to their new height, and an animation interrupted half-way goes on
from where it is instead of snapping. A double click no longer closes
the sheet it just opened
- In the admin, a device's drawer has its own MTU and keep-alive (empty
means the server's), each with a Change dialog. A change touches only
that device's configuration and restarts nothing on the router. Opening
the drawer no longer counts as handing out the configuration: "Update
config" stays until the new configuration is shown as a QR code,
downloaded or copied ("Show the new configuration"). New keys set the
device up again, as the portal's Reconnect does
- "Speed now" on a server's Overview is live: one point a second over the
last two minutes, all there as soon as the Overview opens. The agent
keeps those two minutes in memory and writes them out only while someone
is looking
- Disguise values that AmneziaWG refuses or crashes on are stopped before
they reach the kernel. That covers overlapping H1-H4, Jmin above Jmax,
broken I1-I5 tags, padding under 12 with header protection, and more.
Import and restore refuse them. After a hand edit in uci, the server's
tunnel stays down and Health and the service log say why and what to do.
Errors are full sentences in the reader's language
- The header protection key no longer shows in the status that read-only
users can see: the Server page says only that the key is set, and each
device's configuration still has it. The server no longer turns off
WireGuard's protection against handshake floods (devices keep
DisableCookies). A device can't be added with a server's own key
- An AmneziaWG update whose kernel module can't be swapped (another
AmneziaWG interface holds the old one) no longer fails. It is installed,
the tunnels come back on the old module, and Health and Components say
the update starts after a reboot. On apk firmware, an install that apk
left at the old version counts as failed. A module installed by hand is
recorded, so after a firmware upgrade Health can tell that it is gone
- Dawnline reads only its own tunnels, each one separately. Another
AmneziaWG interface on the router no longer slows the agent's
once-a-second check, has its keys read or breaks Dawnline's reads. A
portal request reads only that person's server: one process however many
servers there are
- Fewer false disconnects: a tunnel that netifd sets up again no longer
logs everyone as leaving and coming back, and a device with a long
keep-alive stays online between handshakes. One configuration on two
devices isn't logged as roaming every few seconds, and new keys end the
old session at once. A tunnel that is missing devices is synced within a
minute, and traffic across a tunnel restart is no longer undercounted
- Renaming a server no longer restarts its tunnel. If a tunnel's interface
is edited outside Dawnline (LuCI, uci), the watchdog sets it up again
with Dawnline's settings and names only the changed options. The routing
rules for "Internet like a home device" change one at a time, new ones
first, so traffic never falls between them. Health and the Server page
warn when the address's AAAA record isn't this router's, or the router
has no public IPv6: devices that prefer IPv6 fail to connect
- The README screenshots come in English and Russian; the portal's are
taken from its demo. The demo has a switch beside × in the set-up sheet
to show each state of the connection line. In Russian, long labels in
the admin's wide option buttons wrap under their icon. DESIGN.md
describes the switch, renaming on the card, the shimmer, the shake and
how the portal scrolls. New tests cover link states, the meter, access,
Health, firewall rules, network settings and packages
This commit is contained in:
1 parent
58492be021
commit
dc0f159447
155 files changed
+11062
-1461
No files matched your search
Executable
+261
@@ -0,0 +1,261 @@
|
||||
#!/usr/bin/env node
|
||||
// Capture the raw README screenshots of the personal portal into
|
||||
// docs/screenshots/raw/ (2x PNG): the page (portal.png) and the three steps of
|
||||
// adding a phone in front of it (portal-add-1..3.png: Add a device, the set-up
|
||||
// sheet waiting, the phone connected), each sheet alone on a transparent page.
|
||||
// The Russian ones take a -ru suffix. scripts/frame-screenshots.py then frames
|
||||
// them for the README.
|
||||
//
|
||||
// The portal is its demo build (web/dist/demo, `npm run build:demo`, built
|
||||
// first unless --no-build): the real portal over a router that lives in the
|
||||
// page, so no one's real page is shown and adding a device adds none. It is
|
||||
// opened as https://vpn.example.com/<code> and every file is answered from the
|
||||
// build over the DevTools protocol (scripts/cdp.mjs), so its personal link
|
||||
// reads like one. The cast is made up here: the demo's own three devices (the
|
||||
// ones its router keeps, so adding one works) under other names, three more
|
||||
// shown beside them, and the person's and the server's names.
|
||||
//
|
||||
// scripts/capture-portal.mjs [--lang en,ru] [--no-build]
|
||||
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { readFileSync, writeFileSync } from 'node:fs';
|
||||
import { dirname, extname, join, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { die, launch, sleep } from './cdp.mjs';
|
||||
|
||||
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const WEB = join(ROOT, 'web');
|
||||
const DEMO = join(WEB, 'dist', 'demo');
|
||||
const RAW = join(ROOT, 'docs', 'screenshots', 'raw');
|
||||
const SCALE = 2;
|
||||
/** The page's width, as the README shot always had it. */
|
||||
const WIDTH = 1320;
|
||||
/** Around a sheet in its capture: left, top, right, bottom (frame-screenshots.py FLOW_MARGIN). */
|
||||
const MARGIN = [56, 40, 56, 72];
|
||||
const ORIGIN = 'https://vpn.example.com';
|
||||
/** The demo's personal link (web/src/portal/demo/index.html, data-base). */
|
||||
const CODE = 'kelino-sarupa-motive';
|
||||
const NAMES = { person: 'Aemeath', server: 'Ames Gateway' };
|
||||
/** The device this page is open on (its card says "This device"). */
|
||||
const HERE = 'MacBook Air';
|
||||
/** The phone added in the steps. */
|
||||
const NEW = 'Pixel 9';
|
||||
const SLOTS = 8;
|
||||
|
||||
const args = { langs: ['en', 'ru'], build: true };
|
||||
for (let i = 2; i < process.argv.length; i++) {
|
||||
const a = process.argv[i];
|
||||
if (a === '--lang') args.langs = (process.argv[++i] ?? die('--lang needs a value')).split(',');
|
||||
else if (a === '--no-build') args.build = false;
|
||||
else die(`unknown argument ${a}`);
|
||||
}
|
||||
|
||||
const DAY = 86400;
|
||||
const now = () => Math.floor(Date.now() / 1000);
|
||||
|
||||
/**
|
||||
* What the demo's router keeps (its DemoDb, in localStorage before the page loads): three devices, so one more
|
||||
* fits its limit of four and the steps add it for real.
|
||||
*/
|
||||
function demoDb(t) {
|
||||
const dev = (id, name, kind, n, gb, hs, days) => ({
|
||||
id,
|
||||
name,
|
||||
kind,
|
||||
n,
|
||||
gb,
|
||||
hs,
|
||||
connectAt: 0,
|
||||
created: t - days * DAY,
|
||||
by: 'admin',
|
||||
stale: false,
|
||||
});
|
||||
return {
|
||||
scenario: 'normal',
|
||||
devs: [
|
||||
dev('d_mac', HERE, 'computer', 2, 5.4, t - 20, 60),
|
||||
dev('d_iph', 'iPhone 16', 'phone', 3, 2.3, t - 40, 58),
|
||||
dev('d_gal', 'Galaxy S24', 'phone', 4, 0.66, t - 26 * 3600, 30),
|
||||
],
|
||||
next: 5,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The page's side, before it loads: the language, the router's devices, the demo's own chrome hidden, and every
|
||||
* answer of its router touched on the way to the page (the names, this device, the slots, the devices shown
|
||||
* beside the ones it keeps).
|
||||
*/
|
||||
const prelude = (lang, db) => `(() => {
|
||||
try {
|
||||
localStorage.setItem('dl.lang', ${JSON.stringify(lang)});
|
||||
localStorage.setItem('dawnline-demo', ${JSON.stringify(JSON.stringify(db))});
|
||||
} catch {}
|
||||
const NAMES = ${JSON.stringify(NAMES)}, HERE = ${JSON.stringify(HERE)}, SLOTS = ${SLOTS};
|
||||
const extra = (devs, t) => {
|
||||
const like = (d, o) => ({ ...d, link: null, setup: null, online: false, config_stale: false, created_by: 'admin', ...o });
|
||||
const mac = devs.find((d) => d.name === HERE) ?? devs[0];
|
||||
const none = { handshake: 0, endpoint: '', month: [0, 0], total: [0, 0], spark: mac.spark.map(() => [0, 0]) };
|
||||
const scale = (p, f) => p.map((v) => Math.round(v * f));
|
||||
return [
|
||||
like(mac, { id: 'x_tv', name: 'Living room TV', kind: 'other', address: '10.8.0.6', handshake: t - 3 * 3600,
|
||||
config_stale: true, month: scale(mac.month, 1.13), total: scale(mac.total, 1.4),
|
||||
spark: mac.spark.map((p) => scale(p, 1.1)), created: t - 45 * 86400 }),
|
||||
like(mac, { id: 'x_ipad', name: 'iPad', kind: 'tablet', address: '10.8.0.7', created: t - 2 * 86400, ...none }),
|
||||
like(mac, { id: 'x_rtr', name: 'Cottage router', kind: 'router', address: '10.8.0.8', created: t - 86400, ...none }),
|
||||
];
|
||||
};
|
||||
const touch = (st) => {
|
||||
if (!st?.person) return;
|
||||
const own = st.person.devices;
|
||||
st.person.name = NAMES.person;
|
||||
if (st.server) st.server.name = NAMES.server;
|
||||
st.person.devices = [...own, ...extra(own, st.now)];
|
||||
st.person.device_limit = SLOTS;
|
||||
st.can_add = st.person.devices.length < SLOTS;
|
||||
st.here = own.find((d) => d.name === HERE)?.id ?? null;
|
||||
};
|
||||
let inner = window.fetch;
|
||||
Object.defineProperty(window, 'fetch', {
|
||||
configurable: true,
|
||||
get: () => inner,
|
||||
// The demo's router takes fetch over (demo/serve.ts): its answers pass through here.
|
||||
set: (f) => {
|
||||
inner = async (...a) => {
|
||||
const r = await f(...a);
|
||||
if (!String(a[0] instanceof Request ? a[0].url : a[0]).includes('/api/')) return r;
|
||||
let j;
|
||||
try { j = await r.clone().json(); } catch { return r; }
|
||||
touch(j?.person ? j : j?.state);
|
||||
return new Response(JSON.stringify(j), { status: r.status, headers: { 'content-type': 'application/json' } });
|
||||
};
|
||||
},
|
||||
});
|
||||
addEventListener('DOMContentLoaded', () => {
|
||||
const s = document.createElement('style');
|
||||
// The demo's chip and GitHub pill go, and the path takes the row again, as on a router's page.
|
||||
s.textContent = '.dm-chip, .dm-gh { display: none !important; } .cr-path { flex: 1 !important; }';
|
||||
document.head.append(s);
|
||||
});
|
||||
})()`;
|
||||
|
||||
const TYPES = { '.html': 'text/html', '.js': 'text/javascript', '.css': 'text/css', '.svg': 'image/svg+xml', '.woff2': 'font/woff2' };
|
||||
|
||||
/** Answer the page's requests from the demo build: its page for the personal link, its files by name. */
|
||||
async function serve(page) {
|
||||
page.on('Fetch.requestPaused', async (e) => {
|
||||
const path = new URL(e.request.url).pathname;
|
||||
const file = path === `/${CODE}` || path === '/' ? 'index.html' : path.slice(1);
|
||||
let body;
|
||||
try {
|
||||
body = readFileSync(join(DEMO, file));
|
||||
} catch {
|
||||
await page.send('Fetch.fulfillRequest', { requestId: e.requestId, responseCode: 404, body: '' }).catch(() => {});
|
||||
return;
|
||||
}
|
||||
await page.send('Fetch.fulfillRequest', {
|
||||
requestId: e.requestId,
|
||||
responseCode: 200,
|
||||
responseHeaders: [{ name: 'Content-Type', value: TYPES[extname(file)] ?? 'application/octet-stream' }],
|
||||
body: body.toString('base64'),
|
||||
});
|
||||
});
|
||||
await page.send('Fetch.enable', { patterns: [{ urlPattern: `${ORIGIN}/*`, requestStage: 'Request' }] });
|
||||
}
|
||||
|
||||
async function shoot(page, file, clip) {
|
||||
const { data } = await page.send('Page.captureScreenshot', {
|
||||
format: 'png',
|
||||
clip: { ...clip, scale: 1 },
|
||||
captureBeyondViewport: true,
|
||||
});
|
||||
writeFileSync(join(RAW, file), Buffer.from(data, 'base64'));
|
||||
console.log(`${file}: ${Math.round(clip.width)}x${Math.round(clip.height)} (x${SCALE})`);
|
||||
}
|
||||
|
||||
// The page's content: everything on screen but full-width or full-height wrappers, 36px around it (as the
|
||||
// README shot always was; what waits off screen, as a field's measuring copy does, is no content).
|
||||
const PAGE_CLIP = `(() => {
|
||||
let l = innerWidth, r = 0, b = 0;
|
||||
for (const e of document.querySelectorAll('#app *')) {
|
||||
const x = e.getBoundingClientRect();
|
||||
if (!x.width || !x.height || x.width > innerWidth - 40 || x.height > innerHeight - 40) continue;
|
||||
if (x.left < 0 || x.right > innerWidth) continue;
|
||||
l = Math.min(l, x.left);
|
||||
r = Math.max(r, x.right);
|
||||
b = Math.max(b, x.bottom);
|
||||
}
|
||||
return { x: l - 36, y: 0, width: r - l + 72, height: b + 40 };
|
||||
})()`;
|
||||
|
||||
// The open sheet alone: the page and the scrim out of sight on a transparent page, MARGIN around the sheet.
|
||||
const SHEET_CLIP = `(() => {
|
||||
const r = document.querySelector('.sheet-root.open .sheet').getBoundingClientRect();
|
||||
const [l, t, rr, b] = ${JSON.stringify(MARGIN)};
|
||||
return { x: r.left - l, y: r.top - t, width: r.width + l + rr, height: r.height + t + b };
|
||||
})()`;
|
||||
const ALONE = `(() => {
|
||||
const s = document.createElement('style');
|
||||
s.id = 'alone';
|
||||
s.textContent = 'html, body { background: transparent !important; } #app { visibility: hidden !important; } .scrim { display: none !important; }';
|
||||
document.head.append(s);
|
||||
})()`;
|
||||
|
||||
async function capture(lang) {
|
||||
const suffix = lang === 'en' ? '' : `-${lang}`;
|
||||
const b = await launch([`--lang=${lang}`]);
|
||||
const { page, evaluate, go, waitSel } = b;
|
||||
try {
|
||||
await page.send('Emulation.setEmulatedMedia', { features: [{ name: 'prefers-color-scheme', value: 'dark' }] });
|
||||
await page.send('Emulation.setDeviceMetricsOverride', { width: WIDTH, height: 1400, deviceScaleFactor: SCALE, mobile: false });
|
||||
// Where the page paints nothing (a sheet alone), the capture is transparent.
|
||||
await page.send('Emulation.setDefaultBackgroundColorOverride', { color: { r: 0, g: 0, b: 0, a: 0 } });
|
||||
await serve(page);
|
||||
await page.send('Page.addScriptToEvaluateOnNewDocument', { source: prelude(lang, demoDb(now())) });
|
||||
await go(`${ORIGIN}/${CODE}`);
|
||||
await waitSel('.dev[data-id]');
|
||||
await sleep(2500);
|
||||
await shoot(page, `portal${suffix}.png`, await evaluate(PAGE_CLIP));
|
||||
|
||||
// 1: Add a device, a phone, its name typed in.
|
||||
await evaluate(`document.querySelector('.dev.add').click()`);
|
||||
await waitSel('.sheet-root.open .kinds');
|
||||
await sleep(900);
|
||||
await evaluate(`document.querySelectorAll('.sheet-root.open .kind')[1].click()`);
|
||||
await sleep(500);
|
||||
await evaluate(`(() => { const i = document.querySelector('.sheet-root.open .field input'); i.focus(); i.select(); })()`);
|
||||
await page.send('Input.insertText', { text: NEW });
|
||||
await evaluate(`document.activeElement.blur()`);
|
||||
await sleep(900);
|
||||
await evaluate(ALONE);
|
||||
await shoot(page, `portal-add-1${suffix}.png`, await evaluate(SHEET_CLIP));
|
||||
await evaluate(`document.getElementById('alone').remove()`);
|
||||
|
||||
// 2: the set-up sheet, waiting for the phone, its link open as a code for the phone's camera (the page
|
||||
// opens on the app's row, whose code a key makes too dense to read at this size).
|
||||
await evaluate(`document.querySelector('.sheet-root.open .field .go').click()`);
|
||||
await waitSel('.sheet-root.open .way');
|
||||
await sleep(1200);
|
||||
await evaluate(`document.querySelector('.sheet-root.open .acc-row:not(.open) .acc-head').click()`);
|
||||
await sleep(1500);
|
||||
await evaluate(ALONE);
|
||||
await shoot(page, `portal-add-2${suffix}.png`, await evaluate(SHEET_CLIP));
|
||||
await evaluate(`document.getElementById('alone').remove()`);
|
||||
|
||||
// 3: connected (the demo's phone does within 6-9 s), what was under the way folded away.
|
||||
await waitSel('.sheet-root.open .way.done', 15000);
|
||||
await sleep(1150);
|
||||
await evaluate(ALONE);
|
||||
await shoot(page, `portal-add-3${suffix}.png`, await evaluate(SHEET_CLIP));
|
||||
page.close();
|
||||
} finally {
|
||||
await b.close();
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
if (args.build) execFileSync('npm', ['run', '--silent', 'build:demo'], { cwd: WEB, stdio: 'inherit' });
|
||||
for (const lang of args.langs) await capture(lang);
|
||||
}
|
||||
|
||||
main().catch((e) => die(e.message));
|
||||
+44
-143
@@ -1,29 +1,33 @@
|
||||
#!/usr/bin/env node
|
||||
// Capture the raw README screenshots from a live router into
|
||||
// Capture the raw README screenshots of the admin pages from a live router into
|
||||
// docs/screenshots/raw/<name>.png (2x PNG); scripts/frame-screenshots.py then
|
||||
// puts them into a browser window for the README.
|
||||
// frames them for the README. The portal's come from its demo instead
|
||||
// (scripts/capture-portal.mjs): no one's real page, and adding a device there adds none.
|
||||
//
|
||||
// Drives a headless Chromium (BROWSER=/path/to/chrome, default: Brave or Chrome
|
||||
// on macOS) over the DevTools protocol, no npm packages. Signs in to LuCI with
|
||||
// on macOS) over the DevTools protocol (scripts/cdp.mjs). Signs in to LuCI with
|
||||
// the password from LUCI_PASSWORD or asked on the terminal; the session lives
|
||||
// only in a throwaway profile (LUCI_USER picks another user than root). Nothing on the router is changed.
|
||||
//
|
||||
// scripts/capture-screenshots.mjs [--router https://router.lan] [--person id]
|
||||
// [--mask real=shown ...] [--name real=shown ...]
|
||||
// [--only overview,people] [--demo]
|
||||
// [--only overview,people] [--demo] [--lang ru]
|
||||
//
|
||||
// --lang asks LuCI for the pages in that language (its catalog, po/<lang>/dawnline.po;
|
||||
// the router's LuCI language left on auto) and names the captures <name>-<lang>.png
|
||||
// for that README (README_ru.md); English (the default) keeps <name>.png.
|
||||
// --mask replaces text on every page before the capture (a domain, a name);
|
||||
// --name does the same for a person's name in any case, and for their initials.
|
||||
// Public IPv4 addresses are always swapped for documentation ones (203.0.113.x).
|
||||
// --demo shows a made-up cast instead of the router's people (scripts/screenshot-demo.mjs):
|
||||
// the router's answers are rewritten in the headless browser on their way to the page.
|
||||
|
||||
import { execFileSync, spawn } from 'node:child_process';
|
||||
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { readFileSync, writeFileSync } from 'node:fs';
|
||||
import { dirname, join, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { createInterface } from 'node:readline';
|
||||
import { die, launch, sleep } from './cdp.mjs';
|
||||
import { demoRpc } from './screenshot-demo.mjs';
|
||||
|
||||
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
||||
@@ -37,6 +41,7 @@ const args = {
|
||||
names: [],
|
||||
only: [],
|
||||
demo: false,
|
||||
lang: 'en',
|
||||
};
|
||||
for (let i = 2; i < process.argv.length; i++) {
|
||||
const a = process.argv[i];
|
||||
@@ -47,8 +52,26 @@ for (let i = 2; i < process.argv.length; i++) {
|
||||
else if (a === '--name') args.names.push(v().split('=', 2));
|
||||
else if (a === '--only') args.only = v().split(',');
|
||||
else if (a === '--demo') args.demo = true;
|
||||
else if (a === '--lang') args.lang = v();
|
||||
else die(`unknown argument ${a}`);
|
||||
}
|
||||
const SUFFIX = args.lang === 'en' ? '' : `-${args.lang}`;
|
||||
|
||||
/** The admin's catalog for --lang: msgid -> msgstr, the entries without a context (English: none). */
|
||||
const CATALOG = (() => {
|
||||
const out = new Map();
|
||||
if (args.lang === 'en') return out;
|
||||
let po;
|
||||
try {
|
||||
po = readFileSync(join(ROOT, 'package', 'luci-app-dawnline', 'po', args.lang, 'dawnline.po'), 'utf8');
|
||||
} catch {
|
||||
die(`no admin catalog for --lang ${args.lang}`);
|
||||
}
|
||||
for (const m of po.matchAll(/^(msgctxt .*\n)?msgid "(.*)"\nmsgstr "(.*)"$/gm)) if (!m[1] && m[3]) out.set(m[2], m[3]);
|
||||
return out;
|
||||
})();
|
||||
/** A button's words as the page shows them in --lang (the pages are clicked by what they say). */
|
||||
const tr = (id) => CATALOG.get(id) ?? id;
|
||||
if ([...args.mask, ...args.names].some((m) => m.length !== 2 || !m[0])) die('--mask and --name take real=shown');
|
||||
|
||||
/** As shared/format initials(): first letters of the first and last word, or the first two of one word. */
|
||||
@@ -60,11 +83,6 @@ for (const [real, shown] of args.names)
|
||||
args.mask.push([real, shown], [real.toLowerCase(), shown.toLowerCase()], [real.toUpperCase(), shown.toUpperCase()]);
|
||||
const INITIALS = args.names.map(([real, shown]) => [initials(real), initials(shown)]);
|
||||
|
||||
function die(msg) {
|
||||
console.error(msg);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const LUCI = `${args.router}/cgi-bin/luci/admin/network/dawnline`;
|
||||
const USER = process.env.LUCI_USER || 'root';
|
||||
|
||||
@@ -93,7 +111,7 @@ const SHOTS = [
|
||||
ready: '.dl-srvov .dl-panel.flush .maplibregl-canvas',
|
||||
// The map shows the last 30 days, not only who is online now.
|
||||
prep: `(() => {
|
||||
const b = [...document.querySelectorAll('.dl-srvov .dl-panel.flush button')].find((x) => x.textContent.trim() === '30 days');
|
||||
const b = [...document.querySelectorAll('.dl-srvov .dl-panel.flush button')].find((x) => x.textContent.trim() === ${JSON.stringify(tr('30 days'))});
|
||||
b?.click();
|
||||
})()`,
|
||||
settle: 6000,
|
||||
@@ -113,7 +131,7 @@ const SHOTS = [
|
||||
ready: '.dl-grid-person .dl-row',
|
||||
// Where they connected from, on the map.
|
||||
prep: `(() => {
|
||||
const b = [...document.querySelectorAll('.dl-grid-person button')].find((x) => x.textContent.trim() === 'Show map');
|
||||
const b = [...document.querySelectorAll('.dl-grid-person button')].find((x) => x.textContent.trim() === ${JSON.stringify(tr('Show map'))});
|
||||
b?.click();
|
||||
})()`,
|
||||
settle: 6000,
|
||||
@@ -131,25 +149,6 @@ const SHOTS = [
|
||||
return { x: c.x, y: 0, width: c.w, height: cut };
|
||||
})()`,
|
||||
},
|
||||
{
|
||||
name: 'portal',
|
||||
url: (s) => s.portal,
|
||||
width: 1320,
|
||||
ready: 'body',
|
||||
settle: 3000,
|
||||
// The content: everything but full-width or full-height wrappers, 36px around it.
|
||||
clip: `(() => {
|
||||
let l = innerWidth, r = 0, b = 0;
|
||||
for (const e of document.body.querySelectorAll('*')) {
|
||||
const x = e.getBoundingClientRect();
|
||||
if (!x.width || !x.height || x.width > innerWidth - 40 || x.height > innerHeight - 40) continue;
|
||||
l = Math.min(l, x.left);
|
||||
r = Math.max(r, x.right);
|
||||
b = Math.max(b, x.bottom);
|
||||
}
|
||||
return { x: l - 36, y: 0, width: r - l + 72, height: b + 40 };
|
||||
})()`,
|
||||
},
|
||||
];
|
||||
|
||||
const MASK = `((pairs, inits) => {
|
||||
@@ -198,87 +197,20 @@ async function password() {
|
||||
}
|
||||
}
|
||||
|
||||
function findBrowser() {
|
||||
const c = [
|
||||
process.env.BROWSER,
|
||||
'/Applications/Brave Browser.app/Contents/MacOS/Brave Browser',
|
||||
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
||||
'/usr/bin/chromium',
|
||||
'/usr/bin/google-chrome',
|
||||
];
|
||||
return c.find((b) => b && existsSync(b)) ?? die('No Chromium-based browser found; set BROWSER=/path/to/chrome');
|
||||
}
|
||||
|
||||
/** A page over the DevTools protocol: send(method, params) and waitFor(event). */
|
||||
async function connect(wsUrl) {
|
||||
const ws = new WebSocket(wsUrl);
|
||||
await new Promise((ok, fail) => {
|
||||
ws.onopen = ok;
|
||||
ws.onerror = fail;
|
||||
});
|
||||
let id = 0;
|
||||
const pending = new Map();
|
||||
const waiters = [];
|
||||
const listeners = [];
|
||||
ws.onmessage = (m) => {
|
||||
const msg = JSON.parse(m.data);
|
||||
if (msg.id && pending.has(msg.id)) {
|
||||
const { ok, fail } = pending.get(msg.id);
|
||||
pending.delete(msg.id);
|
||||
msg.error ? fail(new Error(msg.error.message)) : ok(msg.result);
|
||||
} else if (msg.method) {
|
||||
for (const l of listeners.filter((x) => x.method === msg.method)) l.fn(msg.params);
|
||||
for (const w of waiters.filter((x) => x.method === msg.method)) {
|
||||
waiters.splice(waiters.indexOf(w), 1);
|
||||
w.ok(msg.params);
|
||||
}
|
||||
}
|
||||
};
|
||||
const send = (method, params = {}) =>
|
||||
new Promise((ok, fail) => {
|
||||
pending.set(++id, { ok, fail });
|
||||
ws.send(JSON.stringify({ id, method, params }));
|
||||
});
|
||||
const waitFor = (method) => new Promise((ok) => waiters.push({ method, ok }));
|
||||
const on = (method, fn) => listeners.push({ method, fn });
|
||||
return { send, waitFor, on, close: () => ws.close() };
|
||||
}
|
||||
|
||||
const sleep = (ms) => new Promise((ok) => setTimeout(ok, ms));
|
||||
|
||||
async function main() {
|
||||
const pass = await password();
|
||||
const profile = mkdtempSync(join(tmpdir(), 'dawnline-shots-'));
|
||||
const chrome = spawn(
|
||||
findBrowser(),
|
||||
[
|
||||
'--headless=new',
|
||||
'--remote-debugging-port=0',
|
||||
`--user-data-dir=${profile}`,
|
||||
// The router's certificate is usually for its public name, not router.lan.
|
||||
'--ignore-certificate-errors',
|
||||
'--hide-scrollbars',
|
||||
'--no-first-run',
|
||||
'--no-default-browser-check',
|
||||
// MapLibre needs WebGL; headless gets it from SwiftShader.
|
||||
'--use-angle=swiftshader',
|
||||
'--enable-unsafe-swiftshader',
|
||||
'about:blank',
|
||||
],
|
||||
{ stdio: 'ignore' },
|
||||
);
|
||||
// The router's certificate is usually for its public name, not router.lan.
|
||||
const b = await launch(['--ignore-certificate-errors', `--lang=${args.lang}`]);
|
||||
const { page, evaluate, go, waitSel } = b;
|
||||
try {
|
||||
const portFile = join(profile, 'DevToolsActivePort');
|
||||
for (let i = 0; i < 100 && !existsSync(portFile); i++) await sleep(100);
|
||||
const port = readFileSync(portFile, 'utf8').split('\n')[0];
|
||||
const pages = await (await fetch(`http://127.0.0.1:${port}/json/list`)).json();
|
||||
const page = await connect(pages.find((p) => p.type === 'page').webSocketDebuggerUrl);
|
||||
await page.send('Page.enable');
|
||||
// LuCI on auto speaks the browser's language: this one, whatever this computer's is.
|
||||
await page.send('Network.enable');
|
||||
await page.send('Network.setExtraHTTPHeaders', { headers: { 'Accept-Language': args.lang } });
|
||||
await page.send('Emulation.setEmulatedMedia', {
|
||||
features: [{ name: 'prefers-color-scheme', value: 'dark' }],
|
||||
});
|
||||
// The person shown on the Person page; known once People has loaded (or from --person).
|
||||
const s = { person: args.person, portal: '' };
|
||||
const s = { person: args.person };
|
||||
if (args.demo) {
|
||||
page.on('Fetch.requestPaused', async (e) => {
|
||||
try {
|
||||
@@ -302,27 +234,6 @@ async function main() {
|
||||
});
|
||||
}
|
||||
|
||||
const evaluate = async (expression) => {
|
||||
const r = await page.send('Runtime.evaluate', {
|
||||
expression,
|
||||
awaitPromise: true,
|
||||
returnByValue: true,
|
||||
});
|
||||
if (r.exceptionDetails) throw new Error(r.exceptionDetails.exception?.description ?? r.exceptionDetails.text);
|
||||
return r.result.value;
|
||||
};
|
||||
const go = async (url) => {
|
||||
const loaded = page.waitFor('Page.loadEventFired');
|
||||
await page.send('Page.navigate', { url });
|
||||
await loaded;
|
||||
};
|
||||
const waitSel = async (sel, ms = 20000) => {
|
||||
for (let t = 0; t < ms; t += 250) {
|
||||
if (await evaluate(`!!document.querySelector(${JSON.stringify(sel)})`)) return;
|
||||
await sleep(250);
|
||||
}
|
||||
throw new Error(`timed out waiting for ${sel}`);
|
||||
};
|
||||
// A tall window: Outline scrolls #maincontent, not the page, so it must hold everything.
|
||||
const viewport = (width, height = 2600) =>
|
||||
page.send('Emulation.setDeviceMetricsOverride', {
|
||||
@@ -350,24 +261,16 @@ async function main() {
|
||||
);
|
||||
}
|
||||
|
||||
// The person to show (the first one on People unless --person) and their personal link.
|
||||
// The person to show: the first one on People unless --person.
|
||||
await go(`${LUCI}/server?section=people`);
|
||||
await waitSel('.dl-srvbody a[href*="dawnline/person"]');
|
||||
if (!s.person)
|
||||
s.person = await evaluate(`new URL(document.querySelector('.dl-srvbody a[href*="dawnline/person"]').href).searchParams.get('id')`);
|
||||
s.portal = await evaluate(`L.require('rpc').then((rpc) =>
|
||||
rpc.declare({ object: 'luci.dawnline', method: 'person_links', params: ['id'] })(${JSON.stringify(s.person)}))
|
||||
.then((r) => r.link ?? r.links?.[0] ?? '')`);
|
||||
|
||||
for (const shot of SHOTS) {
|
||||
if (args.only.length && !args.only.includes(shot.name)) continue;
|
||||
const url = shot.url(s);
|
||||
if (!url) {
|
||||
console.log(`skip ${shot.name}: no URL (the portal is off?)`);
|
||||
continue;
|
||||
}
|
||||
await viewport(shot.width);
|
||||
await go(url);
|
||||
await go(shot.url(s));
|
||||
await waitSel(shot.ready);
|
||||
await sleep(2000);
|
||||
if (shot.prep) await evaluate(shot.prep);
|
||||
@@ -379,14 +282,12 @@ async function main() {
|
||||
clip: { ...clip, scale: 1 },
|
||||
captureBeyondViewport: true,
|
||||
});
|
||||
writeFileSync(join(RAW, `${shot.name}.png`), Buffer.from(data, 'base64'));
|
||||
console.log(`${shot.name}: ${Math.round(clip.width)}x${Math.round(clip.height)} (x${SCALE})`);
|
||||
writeFileSync(join(RAW, `${shot.name}${SUFFIX}.png`), Buffer.from(data, 'base64'));
|
||||
console.log(`${shot.name}${SUFFIX}: ${Math.round(clip.width)}x${Math.round(clip.height)} (x${SCALE})`);
|
||||
}
|
||||
page.close();
|
||||
} finally {
|
||||
chrome.kill();
|
||||
await sleep(300);
|
||||
rmSync(profile, { recursive: true, force: true });
|
||||
await b.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
// A headless Chromium driven over the DevTools protocol, no npm packages: what
|
||||
// the README screenshot scripts share (capture-screenshots.mjs from a router,
|
||||
// capture-portal.mjs from the portal demo). BROWSER=/path/to/chrome picks the
|
||||
// browser (default: Brave or Chrome on macOS); its profile is a throwaway one.
|
||||
|
||||
import { spawn } from 'node:child_process';
|
||||
import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { join } from 'node:path';
|
||||
|
||||
export const sleep = (ms) => new Promise((ok) => setTimeout(ok, ms));
|
||||
|
||||
export function die(msg) {
|
||||
console.error(msg);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
export function findBrowser() {
|
||||
const c = [
|
||||
process.env.BROWSER,
|
||||
'/Applications/Brave Browser.app/Contents/MacOS/Brave Browser',
|
||||
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
||||
'/usr/bin/chromium',
|
||||
'/usr/bin/google-chrome',
|
||||
];
|
||||
return c.find((b) => b && existsSync(b)) ?? die('No Chromium-based browser found; set BROWSER=/path/to/chrome');
|
||||
}
|
||||
|
||||
/** A page over the DevTools protocol: send(method, params), waitFor(event) and on(event, fn). */
|
||||
export async function connect(wsUrl) {
|
||||
const ws = new WebSocket(wsUrl);
|
||||
await new Promise((ok, fail) => {
|
||||
ws.onopen = ok;
|
||||
ws.onerror = fail;
|
||||
});
|
||||
let id = 0;
|
||||
const pending = new Map();
|
||||
const waiters = [];
|
||||
const listeners = [];
|
||||
ws.onmessage = (m) => {
|
||||
const msg = JSON.parse(m.data);
|
||||
if (msg.id && pending.has(msg.id)) {
|
||||
const { ok, fail } = pending.get(msg.id);
|
||||
pending.delete(msg.id);
|
||||
msg.error ? fail(new Error(msg.error.message)) : ok(msg.result);
|
||||
} else if (msg.method) {
|
||||
for (const l of listeners.filter((x) => x.method === msg.method)) l.fn(msg.params);
|
||||
for (const w of waiters.filter((x) => x.method === msg.method)) {
|
||||
waiters.splice(waiters.indexOf(w), 1);
|
||||
w.ok(msg.params);
|
||||
}
|
||||
}
|
||||
};
|
||||
const send = (method, params = {}) =>
|
||||
new Promise((ok, fail) => {
|
||||
pending.set(++id, { ok, fail });
|
||||
ws.send(JSON.stringify({ id, method, params }));
|
||||
});
|
||||
const waitFor = (method) => new Promise((ok) => waiters.push({ method, ok }));
|
||||
const on = (method, fn) => listeners.push({ method, fn });
|
||||
return { send, waitFor, on, close: () => ws.close() };
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the browser headless on a fresh profile and connect to its first page. `flags` go on its command line
|
||||
* (a language, certificate errors). Returns the page, its helpers, and close() that ends the browser and removes
|
||||
* the profile.
|
||||
*/
|
||||
export async function launch(flags = []) {
|
||||
const profile = mkdtempSync(join(tmpdir(), 'dawnline-shots-'));
|
||||
const chrome = spawn(
|
||||
findBrowser(),
|
||||
[
|
||||
'--headless=new',
|
||||
'--remote-debugging-port=0',
|
||||
`--user-data-dir=${profile}`,
|
||||
'--hide-scrollbars',
|
||||
'--no-first-run',
|
||||
'--no-default-browser-check',
|
||||
// MapLibre needs WebGL; headless gets it from SwiftShader.
|
||||
'--use-angle=swiftshader',
|
||||
'--enable-unsafe-swiftshader',
|
||||
...flags,
|
||||
'about:blank',
|
||||
],
|
||||
{ stdio: 'ignore' },
|
||||
);
|
||||
const close = async () => {
|
||||
chrome.kill();
|
||||
await sleep(300);
|
||||
rmSync(profile, { recursive: true, force: true });
|
||||
};
|
||||
try {
|
||||
const portFile = join(profile, 'DevToolsActivePort');
|
||||
for (let i = 0; i < 100 && !existsSync(portFile); i++) await sleep(100);
|
||||
const port = readFileSync(portFile, 'utf8').split('\n')[0];
|
||||
const pages = await (await fetch(`http://127.0.0.1:${port}/json/list`)).json();
|
||||
const page = await connect(pages.find((p) => p.type === 'page').webSocketDebuggerUrl);
|
||||
await page.send('Page.enable');
|
||||
const evaluate = async (expression) => {
|
||||
const r = await page.send('Runtime.evaluate', { expression, awaitPromise: true, returnByValue: true });
|
||||
if (r.exceptionDetails) throw new Error(r.exceptionDetails.exception?.description ?? r.exceptionDetails.text);
|
||||
return r.result.value;
|
||||
};
|
||||
const go = async (url) => {
|
||||
const loaded = page.waitFor('Page.loadEventFired');
|
||||
await page.send('Page.navigate', { url });
|
||||
await loaded;
|
||||
};
|
||||
const waitSel = async (sel, ms = 20000) => {
|
||||
for (let t = 0; t < ms; t += 250) {
|
||||
if (await evaluate(`!!document.querySelector(${JSON.stringify(sel)})`)) return;
|
||||
await sleep(250);
|
||||
}
|
||||
throw new Error(`timed out waiting for ${sel}`);
|
||||
};
|
||||
return { page, evaluate, go, waitSel, close };
|
||||
} catch (e) {
|
||||
await close();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,8 @@
|
||||
"""Frame the README screenshots the way the portal draws its own surfaces.
|
||||
|
||||
Raw captures live in docs/screenshots/raw/<name>.png at SCALE device pixels
|
||||
per CSS pixel (scripts/capture-screenshots.mjs takes them); the framed images
|
||||
per CSS pixel (scripts/capture-screenshots.mjs takes the admin's from a router,
|
||||
scripts/capture-portal.mjs the portal's from its demo); the framed images
|
||||
are written to docs/screenshots/<name>.png at the same scale. Each page sits on
|
||||
a panel like the portal's sheets (#121212, radius 36, 16px around it, the page
|
||||
inside at radius 20) on the portal's own black. A shot in FLOWS gets its steps
|
||||
@@ -25,11 +26,12 @@ OUT = os.path.join(ROOT, 'docs', 'screenshots')
|
||||
FONT = os.path.join(ROOT, 'package', 'luci-app-dawnline', 'root', 'usr', 'share', 'dawnline', 'portal', 'assets',
|
||||
'geist-latin-wght-normal.woff2')
|
||||
|
||||
SHOTS = ['overview', 'people', 'person', 'portal']
|
||||
# name -> the steps in front of its page, in order (raw captures). Taken with demo data, not on a router:
|
||||
# adding a device there would add one.
|
||||
SHOTS = ['overview', 'people', 'person', 'portal', 'overview-ru', 'people-ru', 'person-ru', 'portal-ru']
|
||||
# name -> the steps in front of its page, in order (raw captures). The portal's come from its demo
|
||||
# (scripts/capture-portal.mjs), not a router: adding a device there would add one. -ru: README_ru's.
|
||||
FLOWS = {
|
||||
'portal': ['portal-add-1', 'portal-add-2', 'portal-add-3'],
|
||||
'portal-ru': ['portal-add-1-ru', 'portal-add-2-ru', 'portal-add-3-ru'],
|
||||
}
|
||||
PAD_X, PAD_Y, INSET = 96, 80, 16 # canvas around the panel; panel around the page
|
||||
FLOW_MARGIN = (56, 40, 56, 72) # around a step's sheet in its capture: left, top, right, bottom
|
||||
|
||||
@@ -129,16 +129,31 @@ const seen = (when, now) => {
|
||||
}[k] ?? 0
|
||||
);
|
||||
};
|
||||
/** A week of daily totals that adds up to about a quarter of the month, today last (nothing before it was first seen). */
|
||||
/**
|
||||
* A week of daily [rx, tx] that adds up to about a quarter of the month, today last (nothing before it was first
|
||||
* seen), rx (from the device) about an eighth.
|
||||
*/
|
||||
const week = (gb, last, now) =>
|
||||
[0.8, 1.3, 0.6, 1.1, 1.6, 0.9, 1].map((f, i) => (!gb || now - (6 - i) * DAY < last - DAY ? 0 : Math.round(((gb / 4) * f * GB) / 7)));
|
||||
[0.8, 1.3, 0.6, 1.1, 1.6, 0.9, 1].map((f, i) => {
|
||||
const b = !gb || now - (6 - i) * DAY < last - DAY ? 0 : Math.round(((gb / 4) * f * GB) / 7);
|
||||
return [Math.round(b * 0.12), b - Math.round(b * 0.12)];
|
||||
});
|
||||
/**
|
||||
* One second of the cast's traffic through a server (the k-th), [rx, tx] in bytes/s: a few devices streaming,
|
||||
* their uploads small. The same for a second whichever call asks, so the live chart keeps its shape.
|
||||
*/
|
||||
const meterRate = (ts, k) => {
|
||||
const wave = (a, b) => Math.sin(ts / a + k) * 0.45 + Math.sin(ts / b + 2 * k) * 0.25;
|
||||
const noise = (((ts * 7919 + k * 104729) % 1000) / 1000 - 0.5) * 0.35;
|
||||
return [Math.round(Math.max(0, 1.8e5 * (1 + wave(7, 17) + noise))), Math.round(Math.max(0, 1.6e6 * (1 + wave(9, 23) + noise)))];
|
||||
};
|
||||
let ipN = 10;
|
||||
/** A documentation address (the capture swaps public addresses for these anyway). */
|
||||
const ip = () => `203.0.113.${ipN++}`;
|
||||
const where = (city) => `${city} · ${CITIES[city][4]}`;
|
||||
|
||||
/** What the last status made of the router's ids, for the calls that come after it (events, usage). */
|
||||
const demo = { events: [], people: new Map(), days: [], now: 0 };
|
||||
/** What the last status made of the router's ids, for the calls that come after it (events, usage, the meter). */
|
||||
const demo = { events: [], people: new Map(), days: [], now: 0, servers: [] };
|
||||
|
||||
/**
|
||||
* Daily traffic over `days` (oldest first) for `gb` this month: busier some days of the week, today
|
||||
@@ -255,6 +270,12 @@ function demoStatus(st, first) {
|
||||
total: [Math.round(gb * 0.3 * GB), Math.round(gb * 2.2 * GB)],
|
||||
spark: week(gb, hs, now),
|
||||
hostname: hs ? `${slug(name)}.${slug(c.name.split(' ')[0])}.lan` : '',
|
||||
// As set up: nothing failing, its own link values the server's, its data flowing while online.
|
||||
link: null,
|
||||
setup: online ? { state: 'flowing', since: hs } : null,
|
||||
lan_bypass: false,
|
||||
mtu: 0,
|
||||
keepalive: null,
|
||||
};
|
||||
});
|
||||
for (const [name, ago, by] of c.added ?? []) {
|
||||
@@ -313,6 +334,7 @@ function demoStatus(st, first) {
|
||||
demo.events = events;
|
||||
points.sort((a, b) => b.ts - a.ts);
|
||||
demo.now = now;
|
||||
demo.servers = (st.servers ?? []).map((x) => x.id);
|
||||
demo.days = (st.series ?? []).map((x) => x.day);
|
||||
if (!demo.days.length) for (let k = 29; k >= 0; k--) demo.days.push(date(now - k * DAY));
|
||||
const all = CAST.reduce((s, c) => s + c.devices.reduce((t, d) => t + d[3], 0), 0);
|
||||
@@ -384,6 +406,16 @@ export function demoRpc(request, response, first) {
|
||||
},
|
||||
],
|
||||
};
|
||||
// Speed now, live: the last two minutes of the cast's traffic, not the router's.
|
||||
if (method === 'meter' && Array.isArray(data.points)) {
|
||||
const ids = demo.servers.length ? demo.servers : [...new Set(data.points.flatMap((p) => Object.keys(p.servers ?? {})))];
|
||||
const keep = data.keep > 1 ? data.keep : 120;
|
||||
const since = +args?.since || 0;
|
||||
const points = [];
|
||||
for (let ts = data.now - keep + 1; ts <= data.now; ts++)
|
||||
if (ts > since) points.push({ ts, servers: Object.fromEntries(ids.map((id, k) => [id, meterRate(ts, k)])) });
|
||||
return { ...r, result: [r.result[0], { ...data, ts: data.now, points }] };
|
||||
}
|
||||
if (method === 'events' && Array.isArray(data.events)) {
|
||||
const mine = demo.events.filter((e) => !args?.person || e.person === args.person);
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user