From 7522e792422b7d9f9c20e7c26bdc7219eef998f7 Mon Sep 17 00:00:00 2001 From: Lars Gebhardt-Kusche Date: Mon, 8 Dec 2025 00:47:00 +0100 Subject: [PATCH] adasd --- public/assets/js/bridge/blocks-custom.js | 64 ++++++++++++++++++++---- public/version.php | 2 +- src/ApiKernel.php | 17 +++++++ 3 files changed, 71 insertions(+), 12 deletions(-) diff --git a/public/assets/js/bridge/blocks-custom.js b/public/assets/js/bridge/blocks-custom.js index 56e89ba..14b2355 100644 --- a/public/assets/js/bridge/blocks-custom.js +++ b/public/assets/js/bridge/blocks-custom.js @@ -48,29 +48,71 @@ const placeholderSchemaStore = { promise: null, tables: [], + status: null, + statusPromise: null, }; - const fetchPlaceholderSchema = () => { - if (placeholderSchemaStore.promise) return placeholderSchemaStore.promise; + 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.schema`; - placeholderSchemaStore.promise = fetch(url, { credentials: 'include' }) + 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 tbls = data && Array.isArray(data.tables) ? data.tables : []; - placeholderSchemaStore.tables = tbls; - return placeholderSchemaStore.tables; + 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.tables = []; - placeholderSchemaStore.promise = null; - log('PLACEHOLDER ERROR', `Schema konnte nicht geladen werden: ${err.message || err}`, 'red', 'error'); - throw 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 = () => { + 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 sep = base.includes('?') ? '&' : '?'; + const url = `${base}${sep}action=placeholders.schema`; + return fetch(url, { credentials: 'include' }) + .then(res => { + if (!res.ok) throw new Error(`HTTP ${res.status}`); + return res.json(); + }) + .then(data => { + const tbls = data && Array.isArray(data.tables) ? data.tables : []; + placeholderSchemaStore.tables = tbls; + return placeholderSchemaStore.tables; + }); + }).catch(err => { + placeholderSchemaStore.tables = []; + placeholderSchemaStore.promise = null; + 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; + }); return placeholderSchemaStore.promise; }; diff --git a/public/version.php b/public/version.php index a8426f5..62a2de0 100644 --- a/public/version.php +++ b/public/version.php @@ -1,3 +1,3 @@ diff --git a/src/ApiKernel.php b/src/ApiKernel.php index 71c3b7a..b430ccb 100644 --- a/src/ApiKernel.php +++ b/src/ApiKernel.php @@ -856,6 +856,9 @@ class ApiKernel case 'account.bridge.test': $this->handleAccountBridgeTest(); break; + case 'placeholders.status': + $this->handlePlaceholderStatus(); + break; case 'placeholders.schema': $this->handlePlaceholderSchema(); 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 { $cacheFile = $this->placeholderCachePath($url, $token);