bewcloud/routes/calendars.tsx
Bruno Bernardino d86e65475c
Improve App Selection
This allows not enabling Dashboard and Files. It also sorts the apps in the menu according to the order in the `config.core.enabledApps` array.

Since this will require a major version upgrade (`v3.0.0`), I also took the opportunity to upgrade PostgreSQL. You can [follow this guide on how to upgrade PostgreSQL on Docker containers](https://news.onbrn.com/step-by-step-guide-upgrading-postgresql-docker-containers/).

Finally, this has some minor security improvements (confirming API endpoints won't work if their app is disabled in the config).

Closes #114
Closes #108
2025-12-01 12:25:21 +00:00

40 lines
1.1 KiB
TypeScript

import { Handlers, PageProps } from 'fresh/server.ts';
import { FreshContextState } from '/lib/types.ts';
import { Calendar, CalendarModel } from '/lib/models/calendar.ts';
import Calendars from '/islands/calendar/Calendars.tsx';
import { AppConfig } from '/lib/config.ts';
interface Data {
userCalendars: Calendar[];
}
export const handler: Handlers<Data, FreshContextState> = {
async GET(request, context) {
if (!context.state.user) {
return new Response('Redirect', { status: 303, headers: { 'Location': `/login` } });
}
const calendarConfig = await AppConfig.getCalendarConfig();
if (!calendarConfig.enableCalDavServer) {
throw new Error('CalDAV server is not enabled');
}
if (!(await AppConfig.isAppEnabled('calendar'))) {
throw new Error('Calendar app is not enabled');
}
const userCalendars = await CalendarModel.list(context.state.user.id);
return await context.render({ userCalendars });
},
};
export default function CalendarsPage({ data }: PageProps<Data, FreshContextState>) {
return (
<main>
<Calendars initialCalendars={data.userCalendars || []} />
</main>
);
}