30 lines
874 B
TypeScript
30 lines
874 B
TypeScript
// /services/fetchAllTDRChartData.ts
|
|
|
|
const getTDRBasePath = () => {
|
|
if (typeof window !== "undefined") {
|
|
return window.location.hostname === "localhost"
|
|
? "/CPLmockData/LastTDR/jsonDatei"
|
|
: "/CPL?/CPL/LastTDR";
|
|
}
|
|
return "";
|
|
};
|
|
|
|
export const fetchAllTDRChartDataFromServer = async (): Promise<any[]> => {
|
|
const basePath = getTDRBasePath();
|
|
const fileNames = Array.from({ length: 32 }, (_, i) => `slot${i}.json`);
|
|
|
|
const fetchPromises = fileNames.map(async (fileName) => {
|
|
try {
|
|
const response = await fetch(`${basePath}/${fileName}`);
|
|
if (!response.ok)
|
|
throw new Error(`Fehler bei ${fileName}: ${response.statusText}`);
|
|
return await response.json();
|
|
} catch (error) {
|
|
console.error(`Fehler beim Laden von ${fileName}:`, error);
|
|
return null;
|
|
}
|
|
});
|
|
|
|
return await Promise.all(fetchPromises);
|
|
};
|