This commit is contained in:
2025-12-07 00:10:54 +01:00
parent 9d3cf029c3
commit b0485f2e0d

View File

@@ -95,10 +95,10 @@
            return Promise.resolve(B.ApiItemCache[cacheKey]);
        }
        return fetch(url, {
            method: 'GET',
            headers: { 
                'Content-Type': 'application/json' 
return fetch(url, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
            }, 
        })
            .then(response => {
@@ -116,18 +116,28 @@
                    return action === 'get' ? {} : { items: [] };
                }
                
                const result = data.items || data.data || data.item;
                const finalResult = result ? (Array.isArray(result) ? result : (action === 'list' ? (result.items || []) : result)) : (action === 'list' ? [] : {});
const result = data.items || data.data || data.item;
let finalResult = result ? (Array.isArray(result) ? result : (action === 'list' ? (result.items || []) : result)) : (action === 'list' ? [] : {});
                const resultIsArray = Array.isArray(finalResult);
                const resultLength = resultIsArray ? finalResult.length : (Object.keys(finalResult).length > 0 ? 1 : 0);
const resultIsArray = Array.isArray(finalResult);
const resultLength = resultIsArray ? finalResult.length : (Object.keys(finalResult).length > 0 ? 1 : 0);
                log('EXTRACT SUCCESS', `Extrahiert ${resultLength} Elemente (Typ: ${action}) für /${resource}.`);
                
                // Cache-Speicherung verwendet B.ApiItemCache
                if (cacheKey && resultLength > 0) {
                    B.ApiItemCache[cacheKey] = finalResult;
                }
// Bei GET-Antworten stellt der Server häufig html/content separat bereit.
if (action === 'get' && finalResult && !resultIsArray) {
if (data && typeof data.html !== 'undefined' && !('html' in finalResult)) {
finalResult.html = data.html;
}
if (data && typeof data.content !== 'undefined' && !('content' in finalResult)) {
finalResult.content = data.content;
}
}
// Cache-Speicherung verwendet B.ApiItemCache
if (cacheKey && resultLength > 0) {
B.ApiItemCache[cacheKey] = finalResult;
}
                
                // 💡 KORREKTUR: Bei LIST (action='list') geben wir immer ein Array zurück, sonst das Objekt
                return finalResult;