From 52969fd1a89547ec5d4e1880ffaff79fe266fdda Mon Sep 17 00:00:00 2001 From: Kosmos Date: Tue, 25 Aug 2026 16:24:51 +0000 Subject: [PATCH] Remove hard-coded upstream tracking --- Dockerfile | 5 +++ README.md | 9 +++++ docker/remove-analytics.mjs | 56 ++++++++++++++++++++++++++++++ docker/replace-fallback-avatar.mjs | 32 +++++++++++++++++ 4 files changed, 102 insertions(+) create mode 100644 docker/remove-analytics.mjs create mode 100644 docker/replace-fallback-avatar.mjs diff --git a/Dockerfile b/Dockerfile index 4dbe9ac..5734cbc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,6 +15,8 @@ RUN --mount=type=cache,target=/root/.npm npm ci COPY upstream/HubFrontend/ ./ COPY docker/hcaptcha-sitekey.patch /tmp/hcaptcha-sitekey.patch +COPY docker/remove-analytics.mjs /tmp/remove-analytics.mjs +COPY docker/replace-fallback-avatar.mjs /tmp/replace-fallback-avatar.mjs RUN if grep -q 'sitekey="1788882d-3695-4807-abac-7d7166ec6325"' src/routes/auth/login.js; then \ patch -p1 < /tmp/hcaptcha-sitekey.patch; \ @@ -25,6 +27,9 @@ RUN if grep -q 'sitekey="1788882d-3695-4807-abac-7d7166ec6325"' src/routes/auth/ exit 1; \ fi +RUN node /tmp/remove-analytics.mjs +RUN node /tmp/replace-fallback-avatar.mjs + ARG ASSETS_BASE="" ARG VITE_USE_MULTIHUB=false ARG VITE_MULTIHUB_DISCOVERY="" diff --git a/README.md b/README.md index b38c9e8..48ba51b 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,15 @@ example, use `"abbr": "api"` with `"prefix": "/api"`. The frontend uses the Vite values during the image build. Rebuild the image after you change `.env`, including the hCaptcha site key. +The build removes the hard-coded upstream Google Analytics integration and its +consent dialog. If upstream removes the known integration, the build skips this +step. If an unknown Analytics implementation remains, the build stops instead +of publishing it. + +The build also replaces the hard-coded external login avatar with the bundled +`/logo.png` file. If upstream removes the known avatar URL, the build skips this +step. + ## Start the deployment ```bash diff --git a/docker/remove-analytics.mjs b/docker/remove-analytics.mjs new file mode 100644 index 0000000..d97a7f6 --- /dev/null +++ b/docker/remove-analytics.mjs @@ -0,0 +1,56 @@ +import { readFileSync, writeFileSync } from "node:fs"; + +const appPath = "src/App.js"; +let source = readFileSync(appPath, "utf8"); + +const analyticsStart = " const [cookieSettings, setCookieSettings] = useState(localStorage.getItem(\"cookie-settings\"));"; +const analyticsEnd = " const hasSpeedDial ="; +const consentStart = " {!window.isElectron && cookieSettings === null && !sidebarForceHidden && ("; +const consentEnd = " pattern.test(source))) { + throw new Error("An unsupported Analytics implementation remains in src/App.js."); +} + +writeFileSync(appPath, source); diff --git a/docker/replace-fallback-avatar.mjs b/docker/replace-fallback-avatar.mjs new file mode 100644 index 0000000..7f6a950 --- /dev/null +++ b/docker/replace-fallback-avatar.mjs @@ -0,0 +1,32 @@ +import { readFileSync, readdirSync, writeFileSync } from "node:fs"; +import { extname, join } from "node:path"; + +const sourceRoot = "src"; +const upstreamAvatar = "https://charlws.com/me.gif"; +const localAvatar = "/logo.png"; +const sourceExtensions = new Set([".js", ".jsx", ".ts", ".tsx"]); +let replacementCount = 0; + +function updateDirectory(directory) { + for (const entry of readdirSync(directory, { withFileTypes: true })) { + const path = join(directory, entry.name); + if (entry.isDirectory()) { + updateDirectory(path); + } else if (sourceExtensions.has(extname(entry.name))) { + const source = readFileSync(path, "utf8"); + const occurrences = source.split(upstreamAvatar).length - 1; + if (occurrences > 0) { + writeFileSync(path, source.replaceAll(upstreamAvatar, localAvatar)); + replacementCount += occurrences; + } + } + } +} + +updateDirectory(sourceRoot); + +if (replacementCount === 0) { + console.log("Upstream does not contain the known fallback avatar; skip replacement."); +} else { + console.log(`Replaced ${replacementCount} upstream fallback avatar reference(s).`); +}