({ request, user, match, session, isRunningLocally }: RequestHandlerParams)
| 8 | import Loading from '/components/Loading.ts'; |
| 9 | |
| 10 | async function get({ request, user, match, session, isRunningLocally }: RequestHandlerParams) { |
| 11 | if (!(await AppConfig.isAppEnabled('notes'))) { |
| 12 | return new Response('Redirect', { status: 303, headers: { 'Location': `/files` } }); |
| 13 | } |
| 14 | |
| 15 | const searchParams = new URL(request.url).searchParams; |
| 16 | |
| 17 | let currentPath = searchParams.get('path') || '/Notes/'; |
| 18 | |
| 19 | // Send invalid paths back to Notes root |
| 20 | if (!currentPath.startsWith('/Notes/') || currentPath.includes('../')) { |
| 21 | currentPath = '/Notes/'; |
| 22 | } |
| 23 | |
| 24 | // Always append a trailing slash |
| 25 | if (!currentPath.endsWith('/')) { |
| 26 | currentPath = `${currentPath}/`; |
| 27 | } |
| 28 | |
| 29 | const userDirectories = await DirectoryModel.list(user!.id, currentPath); |
| 30 | |
| 31 | const userFiles = await FileModel.list(user!.id, currentPath); |
| 32 | |
| 33 | const userNotes = userFiles.filter((file) => file.file_name.endsWith('.md')); |
| 34 | |
| 35 | const htmlContent = defaultHtmlContent({ userDirectories, userNotes, currentPath }); |
| 36 | |
| 37 | return basicLayoutResponse(htmlContent, { |
| 38 | currentPath: match.pathname.input, |
| 39 | titlePrefix: 'Notes', |
| 40 | match, |
| 41 | request, |
| 42 | user, |
| 43 | session, |
| 44 | isRunningLocally, |
| 45 | }); |
| 46 | } |
| 47 | |
| 48 | function defaultHtmlContent({ userDirectories, userNotes, currentPath }: { |
| 49 | userDirectories: Directory[]; |
nothing calls this directly
no test coverage detected