Update nextcloud.integration.ts

This commit is contained in:
Lorinc936 authored and GitHub committed 2026-03-24 14:44:24 +01:00
1 parent e70d804ab8
commit e78dc86aa3
1 file changed
+21 -17
@@ -5,7 +5,9 @@ import utc from "dayjs/plugin/utc";
import type { RequestInit as NodeFetchRequestInit } from "node-fetch"; import type { RequestInit as NodeFetchRequestInit } from "node-fetch";
import * as ical from "node-ical"; import * as ical from "node-ical";
import { DAVClient } from "tsdav"; import { DAVClient } from "tsdav";
import { z } from "zod";
import { ResponseError } from "@homarr/common/server";
import { fetchWithTrustedCertificatesAsync, createHttpsAgentAsync } from "@homarr/core/infrastructure/http"; import { fetchWithTrustedCertificatesAsync, createHttpsAgentAsync } from "@homarr/core/infrastructure/http";
import { createLogger } from "@homarr/core/infrastructure/logs"; import { createLogger } from "@homarr/core/infrastructure/logs";
@@ -117,26 +119,28 @@ export class NextcloudIntegration extends Integration implements ICalendarIntegr
}, },
}); });
if (!response.ok) { if (!response.ok) throw new ResponseError(response);
throw new Error(`Nextcloud notifications request failed: ${response.status}`);
}
const json = (await response.json()) as { const notificationSchema = z.object({
ocs: { ocs: z.object({
data: { data: z.array(
notification_id: number; z.object({
datetime: string; notification_id: z.number(),
subject: string; datetime: z.string(),
message: string; subject: z.string(),
}[]; message: z.string(),
}; }),
}; ),
}),
});
const json = notificationSchema.parse(await response.json());
return json.ocs.data.map((notification) => ({ return json.ocs.data.map((notification) => ({
id: String(n.notification_id), id: String(notification.notification_id),
time: new Date(n.datetime), time: new Date(notification.datetime),
title: n.subject, title: notification.subject,
body: n.message, body: notification.message,
})); }));
} }