refactor: switch arguments to query parameters
This commit is contained in:
1 parent
9935be7a25
commit
19d2d191d0
1 file changed
+18
-10
@@ -2,9 +2,9 @@ import ical, { VEvent } from 'node-ical';
|
|||||||
import CategoryChart from '@/components/CategoryChart';
|
import CategoryChart from '@/components/CategoryChart';
|
||||||
|
|
||||||
interface PageProps {
|
interface PageProps {
|
||||||
params: Promise<{
|
searchParams: Promise<{
|
||||||
'days': string;
|
'days'?: string;
|
||||||
'ical-link': string[];
|
'ical-link'?: string | string[];
|
||||||
}>;
|
}>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,17 +31,25 @@ function getCategories(categoriesField: any): string[] {
|
|||||||
|
|
||||||
type TimeMap = Record<string, number>;
|
type TimeMap = Record<string, number>;
|
||||||
|
|
||||||
export default async function EvaluationPage({ params }: PageProps) {
|
export default async function EvaluationPage({ searchParams }: PageProps) {
|
||||||
const times: TimeMap = {};
|
const times: TimeMap = {};
|
||||||
let total = 0;
|
let total = 0;
|
||||||
|
|
||||||
const resolvedParams = await params;
|
const resolvedSearchParams = await searchParams;
|
||||||
const daysToFetch = Number(resolvedParams['days']) || 7;
|
const daysToFetch = Number(resolvedSearchParams['days']) || 7;
|
||||||
|
|
||||||
const pathSegments = resolvedParams['ical-link'];
|
const rawUrl = resolvedSearchParams['ical-link'];
|
||||||
let rawUrl = pathSegments.join('/');
|
|
||||||
rawUrl = decodeURIComponent(rawUrl);
|
if (!rawUrl) {
|
||||||
const icalUrl = rawUrl.replace(/^(https?):\/+/, '$1://');
|
return (
|
||||||
|
<div style={{ padding: '1rem', color: '#dc2626', fontFamily: 'system-ui, sans-serif' }}>
|
||||||
|
Fehler: Kein iCal-Link übergeben. Bitte verwende den Query-Parameter ?ical-link=...
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const singleUrl = Array.isArray(rawUrl) ? rawUrl[0] : rawUrl;
|
||||||
|
const icalUrl = decodeURIComponent(singleUrl);
|
||||||
|
|
||||||
const response = await fetch(icalUrl, { next: { revalidate: 3600 } });
|
const response = await fetch(icalUrl, { next: { revalidate: 3600 } });
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
Reference in new issue
Block a user