mirror of
https://github.com/bewcloud/bewcloud.git
synced 2026-03-11 08:54:49 +00:00
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
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import { Handlers, PageProps } from 'fresh/server.ts';
|
|
|
|
import { Dashboard, FreshContextState } from '/lib/types.ts';
|
|
import { DashboardModel } from '/lib/models/dashboard.ts';
|
|
import { AppConfig } from '/lib/config.ts';
|
|
import Notes from '/islands/dashboard/Notes.tsx';
|
|
import Links from '/islands/dashboard/Links.tsx';
|
|
|
|
interface Data {
|
|
userDashboard: Dashboard;
|
|
}
|
|
|
|
export const handler: Handlers<Data, FreshContextState> = {
|
|
async GET(request, context) {
|
|
if (!context.state.user) {
|
|
return new Response('Redirect', { status: 303, headers: { 'Location': `/login` } });
|
|
}
|
|
|
|
if (!(await AppConfig.isAppEnabled('dashboard'))) {
|
|
return new Response('Redirect', { status: 303, headers: { 'Location': `/` } });
|
|
}
|
|
|
|
let userDashboard = await DashboardModel.getByUserId(context.state.user.id);
|
|
|
|
if (!userDashboard) {
|
|
userDashboard = await DashboardModel.create(context.state.user.id);
|
|
}
|
|
|
|
return await context.render({ userDashboard });
|
|
},
|
|
};
|
|
|
|
export default function DashboardPage({ data }: PageProps<Data, FreshContextState>) {
|
|
const initialNotes = data?.userDashboard?.data?.notes || 'Jot down some notes here.';
|
|
|
|
return (
|
|
<main>
|
|
<Links initialLinks={data?.userDashboard?.data?.links || []} />
|
|
|
|
<Notes initialNotes={initialNotes} />
|
|
</main>
|
|
);
|
|
}
|