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
74 lines
2.3 KiB
TypeScript
74 lines
2.3 KiB
TypeScript
import { Handlers, PageProps } from 'fresh/server.ts';
|
|
|
|
import { Directory, DirectoryFile, FreshContextState } from '/lib/types.ts';
|
|
import { DirectoryModel, FileModel } from '/lib/models/files.ts';
|
|
import { AppConfig } from '/lib/config.ts';
|
|
import FilesWrapper from '/islands/files/FilesWrapper.tsx';
|
|
|
|
interface Data {
|
|
userDirectories: Directory[];
|
|
userFiles: DirectoryFile[];
|
|
currentPath: string;
|
|
baseUrl: string;
|
|
isFileSharingAllowed: boolean;
|
|
areDirectoryDownloadsAllowed: boolean;
|
|
}
|
|
|
|
export const handler: Handlers<Data, FreshContextState> = {
|
|
async GET(request, context) {
|
|
if (!context.state.user) {
|
|
return new Response('Redirect', { status: 303, headers: { 'Location': `/login` } });
|
|
}
|
|
|
|
const baseUrl = (await AppConfig.getConfig()).auth.baseUrl;
|
|
|
|
if (!(await AppConfig.isAppEnabled('files'))) {
|
|
return new Response('Redirect', { status: 303, headers: { 'Location': `/` } });
|
|
}
|
|
|
|
const searchParams = new URL(request.url).searchParams;
|
|
|
|
let currentPath = searchParams.get('path') || '/';
|
|
|
|
// Send invalid paths back to root
|
|
if (!currentPath.startsWith('/') || currentPath.includes('../')) {
|
|
currentPath = '/';
|
|
}
|
|
|
|
// Always append a trailing slash
|
|
if (!currentPath.endsWith('/')) {
|
|
currentPath = `${currentPath}/`;
|
|
}
|
|
|
|
const userDirectories = await DirectoryModel.list(context.state.user.id, currentPath);
|
|
|
|
const userFiles = await FileModel.list(context.state.user.id, currentPath);
|
|
|
|
const isPublicFileSharingAllowed = await AppConfig.isPublicFileSharingAllowed();
|
|
const areDirectoryDownloadsAllowed = await AppConfig.areDirectoryDownloadsAllowed();
|
|
|
|
return await context.render({
|
|
userDirectories,
|
|
userFiles,
|
|
currentPath,
|
|
baseUrl,
|
|
isFileSharingAllowed: isPublicFileSharingAllowed,
|
|
areDirectoryDownloadsAllowed,
|
|
});
|
|
},
|
|
};
|
|
|
|
export default function FilesPage({ data }: PageProps<Data, FreshContextState>) {
|
|
return (
|
|
<main>
|
|
<FilesWrapper
|
|
initialDirectories={data.userDirectories}
|
|
initialFiles={data.userFiles}
|
|
initialPath={data.currentPath}
|
|
baseUrl={data.baseUrl}
|
|
isFileSharingAllowed={data.isFileSharingAllowed}
|
|
areDirectoryDownloadsAllowed={data.areDirectoryDownloadsAllowed}
|
|
/>
|
|
</main>
|
|
);
|
|
}
|