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,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;
};

View File

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