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