65 lines
2.1 KiB
PHP
65 lines
2.1 KiB
PHP
<?php
|
|
/**
|
|
* AGENT-AVATARS-V75.PHP — SSOT v2 derived with v75 shape
|
|
*
|
|
* Produces {name: {emoji, svg, url}} from the canonical
|
|
* /api/agent-avatars-v2.json so any page expecting the v75
|
|
* shape (e.g. enterprise-model.html V75 avatar unifier) sees
|
|
* live updates the moment an avatar is changed via the picker.
|
|
*
|
|
* Doctrine: 2 zero régression, 14 enrichir pas écraser, 4 honnêteté
|
|
*/
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
header('Access-Control-Allow-Origin: *');
|
|
header('Access-Control-Allow-Methods: GET, OPTIONS');
|
|
header('Access-Control-Allow-Headers: Content-Type');
|
|
header('Cache-Control: public, max-age=30'); // short cache for quick propagation
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') { http_response_code(204); exit; }
|
|
|
|
$SSOT_V2 = '/var/www/html/api/agent-avatars-v2.json';
|
|
$SVG_EP = '/api/agent-avatar-svg.php';
|
|
|
|
if (!file_exists($SSOT_V2)) {
|
|
http_response_code(500);
|
|
echo json_encode(['error' => 'SSOT v2 missing']);
|
|
exit;
|
|
}
|
|
|
|
$data = json_decode(file_get_contents($SSOT_V2), true);
|
|
if (!is_array($data)) {
|
|
http_response_code(500);
|
|
echo json_encode(['error' => 'SSOT v2 invalid']);
|
|
exit;
|
|
}
|
|
|
|
$out = [];
|
|
foreach ($data as $name => $rec) {
|
|
if (!is_array($rec)) continue;
|
|
$emoji = isset($rec['emoji']) ? (string)$rec['emoji'] : '';
|
|
$url = isset($rec['url']) ? (string)$rec['url'] : '';
|
|
|
|
// v75 shape : emoji + svg (dynamic endpoint) + url
|
|
// DOCTRINE: emoji custom prend priorite sur url heritage
|
|
// (Wave-277: si user set emoji explicite, il override url Dicebear)
|
|
$svg = '';
|
|
if ($emoji !== '') {
|
|
$svg = $SVG_EP . '?n=' . rawurlencode($name) . '&e=' . rawurlencode($emoji);
|
|
} elseif ($url !== '') {
|
|
$svg = $url;
|
|
} else {
|
|
$svg = $SVG_EP . '?n=' . rawurlencode($name) . '&e=' . rawurlencode('👤');
|
|
}
|
|
|
|
// url field: emoji SVG override pour que legacy consumers (img src=url) voient le nouveau
|
|
$final_url = ($emoji !== '') ? $svg : ($url !== '' ? $url : $svg);
|
|
|
|
$out[$name] = [
|
|
'emoji' => $emoji,
|
|
'svg' => $svg,
|
|
'url' => $final_url
|
|
];
|
|
}
|
|
|
|
echo json_encode($out, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|