diff --git a/.projektstructure.txt b/.projektstructure.txt index cccebce..9283b2f 100755 --- a/.projektstructure.txt +++ b/.projektstructure.txt @@ -3,7 +3,7 @@ Anweisung: Projektstruktur (Basis-Template) wie in „papa-kind-treff“ Aktueller Projektstand - Papa-Kind-Treff nutzt im Mitgliederbereich DiceBear `lorelei` über einen internen API-Proxy mit lokalem Cache. - Relevante Logik liegt in `src/App/Avatar/Lorelei.php`. -- Der Avatar-Proxy liegt unter `public/page/api/avatar.php`. +- Der Avatar-Proxy liegt unter `public/api/avatar.php`. - Die visuelle Avatar-Konfiguration liegt im Dashboard-Modal unter `partials/landing/account/dashboard.php` und rendert Komponenten-Vorschauen live nach. - Neue Grundvarianten werden im gleichen Modal als separates Auswahlraster eingeblendet und übernehmen die aktuell gewählten Lorelei-Komponenten. - Alte statische Avatar-Presets und frühere Layer-Assets sind entfernt; aktiv ist nur noch der Lorelei-Generator. diff --git a/PROJECT_CONTEXT.md b/PROJECT_CONTEXT.md index 4bf5047..2c4fc95 100644 --- a/PROJECT_CONTEXT.md +++ b/PROJECT_CONTEXT.md @@ -12,6 +12,7 @@ Papa-Kind-Treff ist eine PHP-basierte Plattform für Väter. Kernbereiche sind l - MySQL/MariaDB-Schema in `schema.sql` - Globales Frontend vor allem über `public/assets/js/app.js` und `public/assets/css/app.css` - Avatar-Style `Lorelei` liegt getrennt unter `src/App/Avatar/Lorelei.php` +- Der Avatar-Endpunkt ist als direkte Datei unter `public/api/avatar.php` angebunden und laeuft bewusst ohne App-Bootstrap. ## Wichtige Produktentscheidungen - Die Ansprache im Frontend soll immer den aktuellen Nutzer direkt ansprechen. diff --git a/README.md b/README.md index 4a3a023..126819a 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ Papa-Kind-Treff ist eine PHP-basierte Plattform für Väter mit Fokus auf lokale Die Rechteverteilung und Community-Logik sind in `src/App/CommunityAccess.php` abgebildet. Die Lorelei-Avatarlogik liegt in `src/App/Avatar/Lorelei.php`. +Der direkte Avatar-Endpunkt liegt in `public/api/avatar.php`. Die visuelle Avatar-Auswahl sitzt im Dashboard-Modal in `partials/landing/account/dashboard.php`. ## Consent und rechtlich relevante Integrationen diff --git a/public/.htaccess b/public/.htaccess index 8ca4b75..292307a 100755 --- a/public/.htaccess +++ b/public/.htaccess @@ -11,6 +11,7 @@ Options -Indexes # 1) Assets DIREKT ausliefern # ------------------------------------------------- RewriteRule ^assets/ - [L] +RewriteRule ^api/ - [L] # ------------------------------------------------- # 2) page/ von außen sperren (nur intern per require nutzbar) diff --git a/public/api/avatar.php b/public/api/avatar.php new file mode 100644 index 0000000..462354b --- /dev/null +++ b/public/api/avatar.php @@ -0,0 +1,62 @@ + $seed, 'size' => '256']; +foreach ($allowedVariantParams as $param) { + $value = Lorelei::normalizeVariant((string)($_GET[$param] ?? '')); + if ($value !== '') { + $query[$param] = $value; + } +} + +foreach ($allowedProbabilityParams as $param) { + $rawValue = (string)($_GET[$param] ?? ''); + if ($rawValue === '') { + continue; + } + + $value = max(0, min(100, (int) $rawValue)); + $query[$param] = (string) $value; +} + +$cacheKey = sha1(json_encode($query, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) ?: $seed); +$cacheFile = $cacheDir . '/' . $cacheKey . '.svg'; +$svg = is_file($cacheFile) ? file_get_contents($cacheFile) : false; + +if ($svg === false) { + $url = 'https://api.dicebear.com/10.x/lorelei/svg?' . http_build_query($query); + $context = stream_context_create([ + 'http' => [ + 'method' => 'GET', + 'timeout' => 2, + 'header' => "User-Agent: Papa-Kind-Treff/1.0\r\nAccept: image/svg+xml\r\n", + ], + ]); + + $remote = @file_get_contents($url, false, $context); + if (is_string($remote) && str_contains($remote, ' { }; const avatarComponentFields = Object.keys(avatarComponentFieldMap); - const avatarEndpoint = '/api/avatar'; + const avatarEndpoint = '/api/avatar.php'; const avatarOptionalProbabilityMap = { avatar_lorelei_glasses_variant: 'glassesProbability', avatar_lorelei_hair_variant: 'hairProbability', diff --git a/src/App/Avatar/Lorelei.php b/src/App/Avatar/Lorelei.php index 13b679d..3a16de0 100644 --- a/src/App/Avatar/Lorelei.php +++ b/src/App/Avatar/Lorelei.php @@ -127,7 +127,7 @@ final class Lorelei public static function buildProxyUrl(array $row): string { - return '/api/avatar?' . http_build_query(self::apiQuery($row)); + return '/api/avatar.php?' . http_build_query(self::apiQuery($row)); } public static function previewChoices(array $row, string $field): array