This commit is contained in:
2025-12-08 00:47:00 +01:00
parent 9ceeecaf4e
commit 7522e79242
3 changed files with 71 additions and 12 deletions

View File

@@ -48,14 +48,51 @@
const placeholderSchemaStore = { const placeholderSchemaStore = {
promise: null, promise: null,
tables: [], tables: [],
status: null,
statusPromise: null,
};
const ensureBridgeAvailability = () => {
if (placeholderSchemaStore.status !== null) {
return Promise.resolve(placeholderSchemaStore.status);
}
if (placeholderSchemaStore.statusPromise) {
return placeholderSchemaStore.statusPromise;
}
const base = B.API_KERNEL_URL || '/api.php';
const sep = base.includes('?') ? '&' : '?';
const url = `${base}${sep}action=placeholders.status`;
placeholderSchemaStore.statusPromise = fetch(url, { credentials: 'include' })
.then(res => {
if (!res.ok) throw new Error(`HTTP ${res.status}`);
return res.json();
})
.then(data => {
const available = !!(data && (data.available || (data.settings && data.settings.available)));
placeholderSchemaStore.status = available;
placeholderSchemaStore.statusPromise = null;
if (!available) {
log('PLACEHOLDER INFO', 'Bridge-Placeholders nicht konfiguriert DB-Funktionen deaktiviert.', '#64748b');
}
return available;
})
.catch(err => {
placeholderSchemaStore.status = false;
placeholderSchemaStore.statusPromise = null;
log('PLACEHOLDER WARN', `Bridge-Status konnte nicht geprüft werden: ${err && err.message ? err.message : err}`, '#b45309');
return false;
});
return placeholderSchemaStore.statusPromise;
}; };
const fetchPlaceholderSchema = () => { const fetchPlaceholderSchema = () => {
if (placeholderSchemaStore.promise) return placeholderSchemaStore.promise; if (placeholderSchemaStore.promise) return placeholderSchemaStore.promise;
placeholderSchemaStore.promise = ensureBridgeAvailability().then(isAvailable => {
if (!isAvailable) throw new Error('Bridge not available');
const base = B.API_KERNEL_URL || '/api.php'; const base = B.API_KERNEL_URL || '/api.php';
const sep = base.includes('?') ? '&' : '?'; const sep = base.includes('?') ? '&' : '?';
const url = `${base}${sep}action=placeholders.schema`; const url = `${base}${sep}action=placeholders.schema`;
placeholderSchemaStore.promise = fetch(url, { credentials: 'include' }) return fetch(url, { credentials: 'include' })
.then(res => { .then(res => {
if (!res.ok) throw new Error(`HTTP ${res.status}`); if (!res.ok) throw new Error(`HTTP ${res.status}`);
return res.json(); return res.json();
@@ -64,11 +101,16 @@
const tbls = data && Array.isArray(data.tables) ? data.tables : []; const tbls = data && Array.isArray(data.tables) ? data.tables : [];
placeholderSchemaStore.tables = tbls; placeholderSchemaStore.tables = tbls;
return placeholderSchemaStore.tables; return placeholderSchemaStore.tables;
}) });
.catch(err => { }).catch(err => {
placeholderSchemaStore.tables = []; placeholderSchemaStore.tables = [];
placeholderSchemaStore.promise = null; placeholderSchemaStore.promise = null;
log('PLACEHOLDER ERROR', `Schema konnte nicht geladen werden: ${err.message || err}`, 'red', 'error'); const msg = err && err.message ? err.message : err;
if (msg === 'Bridge not available') {
log('PLACEHOLDER INFO', 'Schema-Abfrage übersprungen (keine Bridge verfügbar).', '#64748b');
} else {
log('PLACEHOLDER ERROR', `Schema konnte nicht geladen werden: ${msg}`, 'red', 'error');
}
throw err; throw err;
}); });
return placeholderSchemaStore.promise; return placeholderSchemaStore.promise;

View File

@@ -1,3 +1,3 @@
<?php <?php
echo phpinfo();
?> ?>

View File

@@ -856,6 +856,9 @@ class ApiKernel
case 'account.bridge.test': case 'account.bridge.test':
$this->handleAccountBridgeTest(); $this->handleAccountBridgeTest();
break; break;
case 'placeholders.status':
$this->handlePlaceholderStatus();
break;
case 'placeholders.schema': case 'placeholders.schema':
$this->handlePlaceholderSchema(); $this->handlePlaceholderSchema();
break; break;
@@ -1257,6 +1260,20 @@ class ApiKernel
]); ]);
} }
private function handlePlaceholderStatus(): void
{
$user = $this->authService->requireAuth();
$customerId = (int)($user['customer_id'] ?? 0);
$bridge = $this->resolveBridgeConfig($customerId);
$url = trim((string)($bridge['url'] ?? ''));
$token = trim((string)($bridge['token'] ?? ''));
$available = ($url !== '' && $token !== '');
$this->respond([
'ok' => true,
'available' => $available,
]);
}
private function fetchPlaceholderSchema(string $url, string $token, int $ttl): array private function fetchPlaceholderSchema(string $url, string $token, int $ttl): array
{ {
$cacheFile = $this->placeholderCachePath($url, $token); $cacheFile = $this->placeholderCachePath($url, $token);