fix(webui): restore resilient aw-rus ui patching

This commit is contained in:
igor04091968
2026-05-14 23:14:31 +03:00
parent 0098abe426
commit 1399eaf605
4 changed files with 61 additions and 11 deletions
+16
View File
@@ -37,6 +37,17 @@ CATEGORY_HELPER_REPLACEMENT='hostname:t.hostnameChoices.filter((function(t){retu
[[ -f "$HOST_GROUPS_SRC" ]] || { echo "missing $HOST_GROUPS_SRC" >&2; exit 1; }
[[ -f "$INDEX_HTML" ]] || { echo "missing $INDEX_HTML" >&2; exit 1; }
if [[ ! -s "$INDEX_HTML" ]]; then
latest_nonempty_backup="$(find "$WEBUI_DIR" -maxdepth 1 -type f -name 'index.html.bak.*' -size +0c | sort | tail -n 1 || true)"
if [[ -n "$latest_nonempty_backup" ]]; then
cp "$latest_nonempty_backup" "$INDEX_HTML"
echo "restored empty index.html from backup: $latest_nonempty_backup"
else
echo "index.html is empty and no non-empty backup exists: $INDEX_HTML" >&2
exit 1
fi
fi
install -d "$WEBUI_DIR/js"
install -m 0644 "$PATCH_JS_SRC" "$PATCH_TARGET"
install -m 0644 "$SW_CLEANUP_SRC" "$SW_TARGET"
@@ -132,6 +143,11 @@ path.write_text(content)
PY
cp "$SW_CLEANUP_SRC" "$SERVICE_WORKER"
if [[ ! -s "$INDEX_HTML" ]]; then
echo "index.html became empty after RU patch: $INDEX_HTML" >&2
exit 1
fi
trends_chunk="$(grep -Rsl "$TRENDS_NEEDLE" "$WEBUI_DIR/js"/*.js 2>/dev/null | head -n 1 || true)"
if [[ -n "$trends_chunk" ]]; then
cp "$trends_chunk" "$trends_chunk.bak.$TS"
+32 -6
View File
@@ -382,15 +382,23 @@
function enforceSafeActivityViewForPveHost() {
const hash = window.location.hash || "";
const match = hash.match(/^#\/activity\/([^/]+)\/day\/([^/]+)\/view\/([^/?#]+)/i);
const match = hash.match(/^#\/activity\/([^/]+)(?:\/day\/([^/]+))?\/view\/([^/?#]+)/i);
if (!match) return;
const host = decodeURIComponent(match[1] || "");
const day = decodeURIComponent(match[2] || "");
const day = match[2] ? decodeURIComponent(match[2]) : "";
const viewId = decodeURIComponent(match[3] || "");
if (!isPveLikeHost(host)) return;
const safeHash = "#/activity/" + encodeURIComponent(host) + "/day/" + encodeURIComponent(day) + "/view/" + encodeURIComponent("pve_audit");
if (safeHash !== hash && !/^pve_audit$/i.test(viewId)) {
window.location.replace(safeHash);
const prefix = day
? "#/activity/" + encodeURIComponent(host) + "/day/" + encodeURIComponent(day) + "/view/"
: "#/activity/" + encodeURIComponent(host) + "/view/";
if (isPveLikeHost(host)) {
const safeHash = prefix + encodeURIComponent("pve_audit");
if (safeHash !== hash && !/^pve_audit$/i.test(viewId)) {
window.location.replace(safeHash);
}
return;
}
if (/^pve_audit$/i.test(viewId)) {
window.location.replace(prefix + encodeURIComponent("summary"));
}
}
@@ -1542,6 +1550,16 @@
}
}
function hidePveAuditTabForRegularHost(root) {
const hash = window.location.hash || "";
const match = hash.match(/^#\/activity\/([^/]+)/i);
const host = match && match[1] ? decodeURIComponent(match[1]) : "";
if (!host || isPveLikeHost(host)) return;
Array.from(root.querySelectorAll('a[href*="/view/pve_audit"]')).forEach(function (link) {
link.style.display = "none";
});
}
function injectDlpAlertsCenter(root) {
if (!isAlertsRoute()) return;
const host = window.__awRuPatchSettingsHost || getCurrentHostFromHash();
@@ -1578,6 +1596,10 @@
center.setAttribute("data-aw-ru-loaded", "1");
refreshDlpAlertsCenter(center, host);
}
Array.from(heading.parentElement.children).forEach(function (child) {
if (child === heading || child === center) return;
child.style.display = "none";
});
}
let trendsRedirectInFlight = false;
@@ -1646,6 +1668,9 @@
.finally(function () {
settingsHostFetchInFlight = false;
injectDlpNavigation(document.body);
if (isAlertsRoute()) {
scheduleApplyPatch();
}
});
}
@@ -1854,6 +1879,7 @@
walk(document.body);
translateAttributes(document.body);
hideNoiseNavigation(document.body);
hidePveAuditTabForRegularHost(document.body);
patchActivityHeading(document.body);
patchCategoryBuilderHostLabel(document.body);
staticPatchRouteKey = routeKey;
-5
View File
@@ -30,10 +30,5 @@
{ "type": "category_tree", "size": 3, "props": {} },
{ "type": "top_apps", "size": 3, "props": {} }
]
},
{
"id": "pve_audit",
"name": "PVE Audit",
"elements": []
}
]