Der Endpoint nutzte getWebCustomDomains ohne Import → ReferenceError → HTTP 500. server/db/ ist nicht auto-importiert (nur server/utils/), daher expliziter Import wie in allen anderen 15+ db/domains-Konsumenten. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
65 lines
2.1 KiB
TypeScript
65 lines
2.1 KiB
TypeScript
import gamblingDomains from "../../data/gambling-domains.json";
|
|
import { getWebCustomDomains } from "../../db/domains";
|
|
|
|
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,
|
|
};
|
|
});
|