philippurbschat.de/dinos/apis.php
Philipp Urbschat f393beb7ff
feat: inkubator-standard & modul-autodiscovery
- Dynamische Modulerkennung via module.json in ModuleService.php
- Kaskadierender Env-Loader fuer zentrale API-Keys (GEMINI_API_KEY)
- Graceful Auth fuer alle Subprojekte (dinos, plants, storymachine, test)
- Wiederverwendbares Starter-Template in _template/
- test-Modul auf philippurbschat.de Dark-Design modernisiert
2026-09-13 00:23:16 +02:00

112 lines
No EOL
4.7 KiB
PHP

<?php
/*
* Google Gemini API - Model Explorer
* 2026-02-23
*/
// 1. Projekt identifizieren und schützen (Graceful Auth)
$authFile = __DIR__ . '/../auth.php';
if (file_exists($authFile)) {
$current_project = basename(__DIR__);
require_once $authFile;
}
// 2. Nutzerdaten abrufen
$loggedInUser = isset($_SESSION['user_email']) ? $_SESSION['user_email'] : 'Gast';
// Dein API-Key sicher aus .env laden
$apiKey = '';
$envFiles = [__DIR__ . '/.env', __DIR__ . '/../home/.env'];
foreach ($envFiles as $envFile) {
if (file_exists($envFile)) {
foreach (file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) {
$line = trim($line);
if ($line === '' || $line[0] === '#') continue;
if (strpos($line, '=') !== false) {
list($k, $v) = explode('=', $line, 2);
if (trim($k) === 'GEMINI_API_KEY') {
$apiKey = trim(trim($v), '"\'');
break 2;
}
}
}
}
}
$url = "https://generativelanguage.googleapis.com/v1beta/models?key=" . $apiKey;
// Daten abrufen
$response = file_get_contents($url);
$data = json_decode($response, true);
?>
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>API Model Explorer</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-slate-900 text-slate-100 p-8 font-sans">
<div class="max-w-5xl mx-auto">
<header class="mb-8 border-b border-slate-700 pb-4">
<h1 class="text-3xl font-bold text-amber-400">🚀 Google API Model Explorer</h1>
<p class="text-slate-400 mt-2">Diese Modelle sind aktuell für deinen Key freigeschaltet.</p>
</header>
<?php if (isset($data['models'])): ?>
<div class="overflow-x-auto bg-slate-800 rounded-xl shadow-xl border border-slate-700">
<table class="w-full text-left border-collapse">
<thead>
<tr class="bg-slate-700/50 text-amber-300 text-sm uppercase tracking-wider">
<th class="p-4 border-b border-slate-600">ID (für den Code)</th>
<th class="p-4 border-b border-slate-600">Anzeigename</th>
<th class="p-4 border-b border-slate-600 text-xs">Features</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-700">
<?php foreach ($data['models'] as $model):
// Wir entfernen das "models/" Präfix für eine saubere ID
$cleanId = str_replace('models/', '', $model['name']);
?>
<tr class="hover:bg-slate-700/30 transition-colors">
<td class="p-4 font-mono text-pink-400 text-sm">
<span class="bg-slate-900 px-2 py-1 rounded select-all cursor-pointer" title="Klicken zum Markieren">
<?php echo $cleanId; ?>
</span>
</td>
<td class="p-4">
<div class="font-bold text-slate-200"><?php echo $model['displayName']; ?></div>
<div class="text-xs text-slate-500 mt-1 max-w-md"><?php echo $model['description']; ?></div>
</td>
<td class="p-4">
<div class="flex flex-wrap gap-1">
<?php foreach ($model['supportedGenerationMethods'] as $method): ?>
<span class="text-[10px] bg-blue-900/40 text-blue-300 px-2 py-0.5 rounded border border-blue-800/50">
<?php echo $method; ?>
</span>
<?php endforeach; ?>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php else: ?>
<div class="bg-red-900/20 border border-red-500 text-red-400 p-4 rounded-lg">
<strong>Fehler:</strong> Modelle konnten nicht geladen werden. Prüfe deinen API-Key.
</div>
<?php endif; ?>
<footer class="mt-8 text-center text-slate-600 text-xs">
Stand: <?php echo date('d.m.Y H:i'); ?> | Phili's Dino-Labor 🦕
</footer>
</div>
</body>
</html>