Files CRUD.
Remove Contacts and Calendar + CardDav and CalDav.
This commit is contained in:
51
routes/files.tsx
Normal file
51
routes/files.tsx
Normal file
@@ -0,0 +1,51 @@
|
||||
import { Handlers, PageProps } from 'fresh/server.ts';
|
||||
|
||||
import { Directory, DirectoryFile, FreshContextState } from '/lib/types.ts';
|
||||
import { getDirectories, getFiles } from '/lib/data/files.ts';
|
||||
import FilesWrapper from '/islands/files/FilesWrapper.tsx';
|
||||
|
||||
interface Data {
|
||||
userDirectories: Directory[];
|
||||
userFiles: DirectoryFile[];
|
||||
currentPath: string;
|
||||
}
|
||||
|
||||
export const handler: Handlers<Data, FreshContextState> = {
|
||||
async GET(request, context) {
|
||||
if (!context.state.user) {
|
||||
return new Response('Redirect', { status: 303, headers: { 'Location': `/login` } });
|
||||
}
|
||||
|
||||
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 getDirectories(context.state.user.id, currentPath);
|
||||
|
||||
const userFiles = await getFiles(context.state.user.id, currentPath);
|
||||
|
||||
return await context.render({ userDirectories, userFiles, currentPath });
|
||||
},
|
||||
};
|
||||
|
||||
export default function FilesPage({ data }: PageProps<Data, FreshContextState>) {
|
||||
return (
|
||||
<main>
|
||||
<FilesWrapper
|
||||
initialDirectories={data.userDirectories}
|
||||
initialFiles={data.userFiles}
|
||||
initialPath={data.currentPath}
|
||||
/>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user