- 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
59 lines
No EOL
1.7 KiB
PHP
59 lines
No EOL
1.7 KiB
PHP
<?php
|
|
/*
|
|
* 2026-01-08 16:50:00
|
|
* UPLOAD HANDLER
|
|
* Nimmt AJAX Request entgegen und sendet an Google Photos.
|
|
*/
|
|
|
|
$authFile = __DIR__ . '/../auth.php';
|
|
if (file_exists($authFile)) {
|
|
$current_project = basename(__DIR__);
|
|
require_once $authFile;
|
|
}
|
|
require_once 'google_helper.php';
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
// 1. Setup
|
|
$secretFile = 'client_secret.json';
|
|
// Hier wieder DEINE URL eintragen (nur zur Sicherheit, wird hier intern kaum genutzt)
|
|
$redirectUri = 'https://philippurbschat.de/dinos/auth.php';
|
|
|
|
$google = new GoogleHelper($secretFile, $redirectUri);
|
|
|
|
if (!$google->isAuthenticated()) {
|
|
echo json_encode(['success' => false, 'error' => 'Server nicht mit Google verbunden.']);
|
|
exit;
|
|
}
|
|
|
|
// 2. Daten empfangen
|
|
$input = json_decode(file_get_contents('php://input'), true);
|
|
if (!isset($input['image']) || !isset($input['name'])) {
|
|
echo json_encode(['success' => false, 'error' => 'Keine Bilddaten empfangen.']);
|
|
exit;
|
|
}
|
|
|
|
// 3. Base64 bereinigen (Das "data:image/png;base64," entfernen)
|
|
$imgParts = explode(',', $input['image']);
|
|
$base64Data = end($imgParts);
|
|
$binaryImage = base64_decode($base64Data);
|
|
|
|
if (!$binaryImage) {
|
|
echo json_encode(['success' => false, 'error' => 'Bild konnte nicht verarbeitet werden.']);
|
|
exit;
|
|
}
|
|
|
|
// 4. Beschreibung bauen
|
|
$desc = "🦖 " . $input['name'] . "\n" .
|
|
"💡 " . ($input['fun_fact'] ?? '') . "\n" .
|
|
"📅 " . ($input['years'] ?? '');
|
|
|
|
// 5. Hochladen
|
|
$result = $google->uploadImage($binaryImage, $desc);
|
|
|
|
if (isset($result['newMediaItemsResult'])) { // Google Success Structure
|
|
echo json_encode(['success' => true]);
|
|
} else {
|
|
echo json_encode(['success' => false, 'error' => 'Google Fehler', 'details' => $result]);
|
|
}
|
|
?>
|