rebreak-monorepo/backend/server/api/protection/webcontent-domains.get.ts
chahinebrini 9dfccfcbaa fix(protection): webcontent-domains-Endpoint konsolidiert — VIP-Komposition
Ersetzt die statische v1 des Endpoints durch die per-User-VIP-Komposition:
eigene Web-Custom-Domains zuerst + globale Auffuellung → dedup → Cap 50.
v1-Reste entfernt (backend/data/, serverAssets-Eintrag) — eine Datenquelle
(backend/server/data/gambling-domains.json, direkter JSON-Import).
pnpm build:backend gruen verifiziert.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-21 21:21:22 +02:00

64 lines
2.0 KiB
TypeScript

import gamblingDomains from "../../data/gambling-domains.json";
const COUNTRY_KEYS = ["DE", "GB", "FR"] as const;
type CountryKey = (typeof COUNTRY_KEYS)[number];
const GLOBAL_LISTS = gamblingDomains as Record<string, string[]> & {
_meta: (typeof gamblingDomains)["_meta"];
};
const MAX_PER_COUNTRY = 50;
/**
* GET /api/protection/webcontent-domains
*
* Liefert die VIP-Domain-Liste für den WebKit-webContent-Filter (Layer 2).
* Pro User personalisiert:
* Custom-Web-Domains (aktiv, nicht approved/rejected) + globale Liste
* → dedupliziert → hart auf 50 gekappt (Apple-Limit).
*
* Custom-Domains stehen vorne (User-Priorität).
* Response-Shape ist identisch mit der statischen Version — iOS parst das unverändert.
*
* Lade-Mechanismus: direkter JSON-Import (build-time gebundelt via Nitro-Bundler).
* Kein serverAssets/useStorage — kein extra Laufzeit-I/O, kein globales
* backend/data/-Verzeichnis nötig.
*
* Pflege: backend/server/data/gambling-domains.json editieren,
* _meta.version hochzählen, _meta.updatedAt setzen, dann neu deployen.
*/
export default defineEventHandler(async (event) => {
const user = await requireUser(event);
// Custom Web-Domains des Users laden — parallel zu allen Country-Listen
const userWebDomains = await getWebCustomDomains(user.id);
const userWebSet = new Set(userWebDomains);
// Pro Country: Custom-Domains vorne, dann globale Auffüllung, dedup, cap 50
const composed: Record<CountryKey, string[]> = {} as Record<
CountryKey,
string[]
>;
for (const country of COUNTRY_KEYS) {
const globalList: string[] = GLOBAL_LISTS[country] ?? [];
// Custom-Domains zuerst (bereits dedupliziert da aus DB)
const merged: string[] = [...userWebDomains];
// Globale Domains auffüllen — nur wenn noch nicht durch Custom drin
for (const domain of globalList) {
if (!userWebSet.has(domain)) {
merged.push(domain);
}
}
composed[country] = merged.slice(0, MAX_PER_COUNTRY);
}
return {
_meta: gamblingDomains._meta,
...composed,
};
});