feature: improve calendar

This commit is contained in:
WonderAliceUwU committed 2026-07-10 19:50:22 +02:00
1 parent f40e1248b5
commit 8596293345
5 files changed
+402 -80

No files matched your search

+29 -1
View File
@@ -234,7 +234,35 @@ async function routeRequest(request: IncomingMessage, response: ServerResponse):
if (url.pathname === '/api/calendar' && method === 'GET') {
const config = await readConfig(session!.encryptionKey);
sendJson(response, 200, await getCalendar(config));
const startParam = url.searchParams.get('start');
const endParam = url.searchParams.get('end');
let start = new Date();
start.setDate(1);
start.setHours(0, 0, 0, 0);
let end = new Date(start);
end.setMonth(end.getMonth() + 1);
end.setDate(0);
end.setHours(23, 59, 59, 999);
if (startParam) {
try {
start = new Date(startParam);
} catch (e) {
// ignore invalid date
}
}
if (endParam) {
try {
end = new Date(endParam);
} catch (e) {
// ignore invalid date
}
}
sendJson(response, 200, await getCalendar(config, start, end));
return;
}
+3 -5
View File
@@ -523,9 +523,7 @@ export async function getDownloads(config: AppConfig): Promise<DownloadItem[]> {
return downloads.sort((a, b) => b.progress - a.progress);
}
export async function getCalendar(config: AppConfig): Promise<CalendarResponse> {
const start = startOfToday()
const end = addDays(start, 30)
export async function getCalendar(config: AppConfig, start: Date, end: Date): Promise<CalendarResponse> {
const [sonarrResult, radarrResult] = await Promise.allSettled([
getSonarrCalendar(config, start, end),
@@ -3196,7 +3194,7 @@ async function getSonarrCalendar(config: AppConfig, start: Date, end: Date): Pro
}
return fetchJson<SonarrCalendarRecord[]>(
`${config.sonarr.baseUrl}/api/v3/calendar?includeSeries=true&start=${encodeURIComponent(start.toISOString())}&end=${encodeURIComponent(end.toISOString())}`,
`${config.sonarr.baseUrl}/api/v3/calendar?includeSeries=true&unmonitored=true&start=${encodeURIComponent(start.toISOString())}&end=${encodeURIComponent(end.toISOString())}`,
{
headers: {
'X-Api-Key': config.sonarr.apiKey
@@ -3211,7 +3209,7 @@ async function getRadarrCalendar(config: AppConfig, start: Date, end: Date): Pro
}
return fetchJson<RadarrCalendarRecord[]>(
`${config.radarr.baseUrl}/api/v3/calendar?start=${encodeURIComponent(start.toISOString())}&end=${encodeURIComponent(end.toISOString())}`,
`${config.radarr.baseUrl}/api/v3/calendar?unmonitored=true&start=${encodeURIComponent(start.toISOString())}&end=${encodeURIComponent(end.toISOString())}`,
{
headers: {
'X-Api-Key': config.radarr.apiKey