aktueller stand

This commit is contained in:
2026-01-04 00:11:29 +01:00
parent 41ef5107aa
commit 1c12bf6bd1
9 changed files with 1013 additions and 69 deletions

View File

@@ -357,7 +357,7 @@ async function checkEntry(sessionId, entry, settings) {
try {
const pickups = await withSessionRetry(
session,
() => foodsharingClient.fetchPickups(entry.id, session.cookieHeader),
() => foodsharingClient.fetchPickups(entry.id, session.cookieHeader, session),
{ label: 'fetchPickups' }
);
let hasProfileId = false;
@@ -428,7 +428,7 @@ async function checkWatchedStores(sessionId, settings = DEFAULT_SETTINGS, option
try {
const details = await withSessionRetry(
session,
() => foodsharingClient.fetchStoreDetails(watcher.storeId, session.cookieHeader),
() => foodsharingClient.fetchStoreDetails(watcher.storeId, session.cookieHeader, session),
{ label: 'fetchStoreDetails' }
);
const status = details?.teamSearchStatus === 1 ? 1 : 0;
@@ -578,6 +578,19 @@ async function runStoreWatchCheck(sessionId, settings, options = {}) {
return checkWatchedStores(sessionId, resolvedSettings, options);
}
async function runImmediatePickupCheck(sessionId, config, settings) {
const resolvedSettings = resolveSettings(settings);
const entries = Array.isArray(config) ? config : [];
const activeEntries = entries.filter((entry) => entry?.active);
if (activeEntries.length === 0) {
return { checked: 0 };
}
for (const entry of activeEntries) {
await checkEntry(sessionId, entry, resolvedSettings);
}
return { checked: activeEntries.length };
}
function setMonthOffset(date, offset) {
const copy = new Date(date.getTime());
copy.setMonth(copy.getMonth() + offset);
@@ -593,11 +606,14 @@ function getMissingLastPickupStoreIds(config = []) {
.map((entry) => String(entry.id));
}
async function checkDormantMembers(sessionId) {
async function checkDormantMembers(sessionId, options = {}) {
const session = sessionStore.get(sessionId);
if (!session?.profile?.id) {
return;
}
const storeIdSet = Array.isArray(options.storeIds)
? new Set(options.storeIds.map((storeId) => String(storeId)))
: null;
const profileId = session.profile.id;
const ensured = await ensureSession(session);
if (!ensured) {
@@ -615,26 +631,54 @@ async function checkDormantMembers(sessionId) {
});
let configChanged = false;
const storeTargets = new Map();
config.forEach((entry) => {
if (!entry?.id || entry.hidden) {
return;
}
const storeId = String(entry.id);
if (storeIdSet && !storeIdSet.has(storeId)) {
return;
}
if (skipMap.get(storeId)) {
return;
}
storeTargets.set(storeId, {
storeId,
storeName: entry.label || `Store ${storeId}`
});
});
const stores = Array.isArray(session.storesCache?.data) ? session.storesCache.data : [];
if (stores.length === 0) {
console.warn(`[DORMANT] Keine Stores für Session ${sessionId} im Cache gefunden.`);
} else {
stores.forEach((store) => {
const storeId = store?.id ? String(store.id) : null;
if (!storeId || !storeTargets.has(storeId)) {
return;
}
const target = storeTargets.get(storeId);
storeTargets.set(storeId, {
...target,
storeName: store.name || target.storeName
});
});
}
if (storeTargets.size === 0) {
return;
}
const fourMonthsAgo = setMonthOffset(new Date(), -4).getTime();
const hygieneCutoff = Date.now() + 6 * 7 * 24 * 60 * 60 * 1000;
for (const store of stores) {
const storeId = store?.id ? String(store.id) : null;
if (!storeId) {
continue;
}
if (skipMap.get(storeId)) {
continue;
}
for (const target of storeTargets.values()) {
const storeId = target.storeId;
let members = [];
try {
members = await withSessionRetry(
session,
() => foodsharingClient.fetchStoreMembers(storeId, session.cookieHeader),
() => foodsharingClient.fetchStoreMembers(storeId, session.cookieHeader, session),
{ label: 'fetchStoreMembers' }
);
} catch (error) {
@@ -671,7 +715,7 @@ async function checkDormantMembers(sessionId) {
try {
await sendDormantPickupWarning({
profileId,
storeName: store.name || `Store ${storeId}`,
storeName: target.storeName,
storeId,
reasonLines: reasons
});
@@ -722,7 +766,13 @@ function scheduleDormantMembershipCheck(sessionId) {
setTimeout(() => checkDormantMembers(sessionId), randomDelayMs(30, 180));
}
async function runDormantMembershipCheck(sessionId, options = {}) {
await checkDormantMembers(sessionId, options);
}
module.exports = {
scheduleConfig,
runStoreWatchCheck
runStoreWatchCheck,
runImmediatePickupCheck,
runDormantMembershipCheck
};