fix(geplante-nachrichten): cache rooms response 60s and pass Nextcloud errors through to frontend

This commit is contained in:
Matthias Hochmeister
2026-04-17 13:33:07 +02:00
parent 53c8be0f6d
commit d44f53a8a9

View File

@@ -309,14 +309,19 @@ async function remove(id: string): Promise<boolean> {
// ── Rooms ────────────────────────────────────────────────────────────────────
let roomsCache: { result: RoomsResult; expiresAt: number } | null = null;
async function getRooms(): Promise<RoomsResult> {
if (roomsCache && Date.now() < roomsCache.expiresAt) {
return roomsCache.result;
}
const creds = await getBotCredentials();
if (!creds) {
return { configured: false };
}
try {
const conversations = await nextcloudService.getAllConversations(creds.username, creds.appPassword);
return {
const result: RoomsResult = {
configured: true,
data: conversations.map(c => ({
token: c.token,
@@ -324,10 +329,12 @@ async function getRooms(): Promise<RoomsResult> {
type: c.type,
})),
};
roomsCache = { result, expiresAt: Date.now() + 60_000 };
return result;
} catch (error) {
const msg = error instanceof Error ? error.message : String(error);
logger.error('scheduledMessages.getRooms failed', { error: msg });
return { configured: true, data: [], error: msg };
return { configured: true, data: [], error: 'Verbindung zu Nextcloud fehlgeschlagen' };
}
}