Better mesh empty page (#1505)

* Fix mesh data syntax error when page is empty

* Make sure we have at least one host to show on the mesh page
This commit is contained in:
Tim Wilkinson 2024-09-13 21:16:16 -07:00 committed by GitHub
parent c0e154794b
commit 2bfad694d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 1 deletions

View File

@ -45,11 +45,16 @@ const h = fs.open("/var/run/hosts_olsr");
if (h) {
let originator = null;
let first = true;
let fallback = null;
for (let line = h.read("line"); length(line); line = h.read("line")) {
const v = match(trim(line), reHostsOlsr);
if (v) {
if (originator !== v[3]) {
if (originator) {
if (first && fallback) {
print(`["${fallback}"]`);
}
fallback = null;
print("],");
}
originator = v[3];
@ -75,8 +80,14 @@ if (h) {
}
first = false;
}
else if (originator === "myself" && index(host, "dtdlink") === 0) {
fallback = replace(host, /^dtdlink\.(.+)\.local\.mesh$/, "$1");
}
}
}
if (first && fallback) {
print(`["${fallback}"]`);
}
print("]");
h.close();
}
@ -108,7 +119,9 @@ if (s) {
first = false;
}
}
print("]");
if (ip) {
print("]");
}
s.close();
}
print(`},etx:[["${myself}",0.0],`);