MCPcopy Create free account
hub / github.com/bewcloud/bewcloud / get

Function get

pages/notes.ts:10–46  ·  view source on GitHub ↗
({ request, user, match, session, isRunningLocally }: RequestHandlerParams)

Source from the content-addressed store, hash-verified

8import Loading from '/components/Loading.ts';
9
10async 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
48function defaultHtmlContent({ userDirectories, userNotes, currentPath }: {
49 userDirectories: Directory[];

Callers

nothing calls this directly

Calls 5

basicLayoutResponseFunction · 0.90
isAppEnabledMethod · 0.80
defaultHtmlContentFunction · 0.70
getMethod · 0.45
listMethod · 0.45

Tested by

no test coverage detected