43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* Sendet GET-Anfrage an /api/get-analysis und gibt geparste JSON-Daten zurück.
|
|
* @param {Object} [options] - Optionales Filterobjekt { filter: 'idle' | 'load' }
|
|
* @returns {Promise<Object>} - Promise, das das Analyse-Datenobjekt liefert
|
|
*/
|
|
export async function fetchAnalysisData(options = {}) {
|
|
const endpoint = '/api/get-analysis';
|
|
const params = new URLSearchParams();
|
|
|
|
if (options.filter && (options.filter === 'idle' || options.filter === 'load')) {
|
|
params.append('filter', options.filter);
|
|
}
|
|
|
|
const url = params.toString() ? `${endpoint}?${params.toString()}` : endpoint;
|
|
|
|
try {
|
|
const response = await fetch(url, {
|
|
method: 'GET',
|
|
headers: {
|
|
'Accept': 'application/json'
|
|
}
|
|
});
|
|
|
|
if (!response.ok) {
|
|
console.error(`API-Fehler: ${response.status} ${response.statusText}`);
|
|
throw new Error(`Fehler beim Abrufen der Analyse: ${response.status}`);
|
|
}
|
|
|
|
const data = await response.json();
|
|
|
|
if (!data || typeof data !== 'object' || !Array.isArray(data.runs)) {
|
|
console.error('Unerwartetes Datenformat von /api/get-analysis:', data);
|
|
throw new Error('Ungültige Datenstruktur von der API');
|
|
}
|
|
|
|
return data;
|
|
} catch (error) {
|
|
console.error('Fehler beim Abruf der Analysedaten:', error);
|
|
throw error;
|
|
}
|
|
}
|