aktueller Stand

This commit is contained in:
root
2025-11-09 14:46:36 +01:00
parent cd93800ffb
commit e90f9299c3
4 changed files with 46 additions and 8 deletions

View File

@@ -124,11 +124,8 @@ async function fetchStores(cookieHeader, profileId) {
headers: buildHeaders(cookieHeader),
params: { activeStores: 1 }
});
const stores = response.data || [];
if (!Array.isArray(stores)) {
return [];
}
return stores.map((store) => ({
const stores = Array.isArray(response.data) ? response.data : [];
const normalized = stores.map((store) => ({
id: String(store.id),
name: store.name || `Store ${store.id}`,
pickupStatus: store.pickupStatus,
@@ -138,12 +135,45 @@ async function fetchStores(cookieHeader, profileId) {
street: store.street || '',
zip: store.zip || ''
}));
return annotateStoresWithPickupSlots(normalized, cookieHeader);
} catch (error) {
console.warn('Stores konnten nicht geladen werden:', error.message);
return [];
}
}
async function annotateStoresWithPickupSlots(stores, cookieHeader, concurrency = 5) {
if (!Array.isArray(stores) || stores.length === 0) {
return [];
}
const cappedConcurrency = Math.max(1, Math.min(concurrency, stores.length));
const results = new Array(stores.length);
let pointer = 0;
async function worker() {
while (true) {
const currentIndex = pointer++;
if (currentIndex >= stores.length) {
return;
}
const store = stores[currentIndex];
let hasPickupSlots = null;
try {
const pickups = await fetchPickups(store.id, cookieHeader);
hasPickupSlots = Array.isArray(pickups) && pickups.length > 0;
} catch (error) {
console.warn(`Pickups für Store ${store.id} konnten nicht geprüft werden:`, error.message);
}
results[currentIndex] = { ...store, hasPickupSlots };
}
}
await Promise.all(Array.from({ length: cappedConcurrency }, () => worker()));
return results;
}
async function fetchPickups(storeId, cookieHeader) {
const response = await client.get(`/api/stores/${storeId}/pickups`, {
headers: buildHeaders(cookieHeader)