drop/server/plugins/telemetry.client.ts
wdunn001 faa8b7d61c
Some checks are pending
Deploy website to GitHub Pages / deploy (push) Blocked by required conditions
Deploy website to GitHub Pages / build (push) Waiting to run
Server CI / Typecheck (push) Waiting to run
Server CI / Lint (push) Waiting to run
community: fold /community into the fork, source-build the three JS patches
Replaces the server/pages/community.vue stub ({{ $t("todo") }}) with real
Nuxt pages: a unified Drop+RomM title browser, an admin catalog-sync panel,
and a profile page with playtime rails. Corrects the original architecture
mistake of building this as a separate service at community.quasarke.net --
now that we own the fork's source, community is ordinary Nuxt pages instead
of a sidecar with its own auth/DB/vhost.

Data model: one new table, CommunityTitle, for the RomM catalog (ported
from drop-community M1's Title spine). Drop's own Game/User/Playtime models
already ARE the title/identity/playtime spine for Drop content, so nothing
new was needed there -- profile playtime rails read real, already-existing
Playtime rows, no wrapper/ingest milestone required to populate them.
RommAdapter (server/server/internal/community/rommAdapter.ts) reads RomM's
MariaDB directly via the community_ro read-only role, same deviation and
same reasoning as M1's adapter (RomM's /api/roms needs a browser session,
no service-account key). TitleSyncService runs every 6h
(scheduledTasks.communityTitleSync) and via an admin "Sync now" button
(system:community:sync ACL) -- never deletes, hides instead.

Also folds the three post-build JS patches
(homelab-compose/drop-stack/patch-{launcher-button,telemetry-snippet,
footer-links}.js) into source now that the fork builds from source instead
of patching upstream's prebuilt image:
  - library/game/[id]/index.vue: the "Open in Launcher" button gets a real
    @click handler (drop://open with a timeout fallback to /download).
  - plugins/telemetry.client.ts: OpenPanel RUM injected via a Nuxt client
    plugin instead of appending to the compiled entry chunk.
  - UserFooter.vue + admin/library source-help links + error.vue + the
    Weblate link: repointed at our own infra. The Discord/social link
    used to point at community.quasarke.net; that service is retired, so
    it now points at /community directly.
2026-08-02 00:12:06 -04:00

40 lines
1.6 KiB
TypeScript

// OpenPanel RUM snippet -- folded into source now that we build the fork
// from source rather than patching upstream's prebuilt image (see the
// now-removed homelab-compose drop-stack/patch-telemetry-snippet.js for the
// original: Drop is LAN-only behind the .88 Caddy, so the .198 nginx-proxy
// sub_filter injection used for the public sites never sees it, and the
// frontend is SSR'd per request so there's no static HTML to inject into
// either -- a client plugin covers every page exactly once per full load,
// and Nuxt's own router hooks stand in for OpenPanel's trackScreenViews on
// SPA navigations).
//
// Client id is a PUBLIC write key (no secret), scoped by CORS origin on the
// telemetry side -- safe to ship in the bundle, same as before.
export default defineNuxtPlugin(() => {
const config = useRuntimeConfig();
const clientId = config.public.telemetry?.clientId;
const apiUrl = config.public.telemetry?.apiUrl;
if (!clientId || !apiUrl) return;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const w = window as any;
if (w.__opTelemetry) return;
w.__opTelemetry = 1;
w.op =
w.op ||
function (...args: unknown[]) {
(w.op.q = w.op.q || []).push(args);
};
w.op("init", {
clientId,
apiUrl: `${apiUrl}/v1`,
trackScreenViews: true,
trackOutgoingLinks: true,
trackAttributes: true,
});
const script = document.createElement("script");
script.src = `${apiUrl}/assets/site.js`;
script.async = true;
script.defer = true;
(document.head || document.documentElement).appendChild(script);
});