mirror of
https://github.com/bewcloud/bewcloud.git
synced 2026-03-11 08:54:49 +00:00
This implements a huge change, where Fresh is removed as a framework and serving files, allowing more control over importing, bundling, and serving files and components. The biggest challenge was to continue making sure that there weren't too many places to look into for import versions, and `PasswordlessPasskeyLogin.tsx` became a prototype in migrating a component to fully SSR, no need for frontend parsing (via Babel) or bundling (via a custom-script, downloading frontend dependencies from esm.sh). Still, there are too many components to migrate like that, and it's all working, so I likely won't even attempt it unless there's some bug, new feature, or security vulnerability to address that warrants a rewrite of those. This also updates all dependencies (except `@libs/xml` because that still causes some breaking in DAV endpoints), including Deno! All other advantages can be seen in the related issues, and the breaking change this (v4.0.0) introduces is related simply to `config.email.tlsMode` (which had a deprecation warning throughout v3), and because, while I tested many things exhaustively, it's not impossible something broke that I didn't see. Closes #141 Closes #132
67 lines
1.7 KiB
TypeScript
67 lines
1.7 KiB
TypeScript
import page, { RequestHandlerParams } from '/lib/page.ts';
|
|
|
|
import { FileModel } from '/lib/models/files.ts';
|
|
import { AppConfig } from '/lib/config.ts';
|
|
|
|
export interface RequestBody {
|
|
fileName: string;
|
|
currentPath: string;
|
|
contents: string;
|
|
}
|
|
|
|
export interface ResponseBody {
|
|
success: boolean;
|
|
}
|
|
|
|
async function post({ request, user }: RequestHandlerParams) {
|
|
if (!(await AppConfig.isAppEnabled('notes'))) {
|
|
return new Response('Forbidden', { status: 403 });
|
|
}
|
|
|
|
const requestBody = await request.clone().json() as RequestBody;
|
|
|
|
if (
|
|
!requestBody.currentPath || !requestBody.fileName || !requestBody.currentPath.startsWith('/Notes/') ||
|
|
requestBody.currentPath.includes('../') || !requestBody.currentPath.endsWith('/')
|
|
) {
|
|
return new Response('Bad Request', { status: 400 });
|
|
}
|
|
|
|
if (
|
|
!requestBody.currentPath || !requestBody.currentPath.startsWith('/Notes/') ||
|
|
requestBody.currentPath.includes('../')
|
|
) {
|
|
return new Response('Bad Request', { status: 400 });
|
|
}
|
|
|
|
// Don't allow non-markdown files here
|
|
if (!requestBody.fileName.endsWith('.md')) {
|
|
return new Response('Not Found', { status: 404 });
|
|
}
|
|
|
|
const fileResult = await FileModel.get(
|
|
user!.id,
|
|
requestBody.currentPath,
|
|
decodeURIComponent(requestBody.fileName),
|
|
);
|
|
|
|
if (!fileResult.success) {
|
|
return new Response('Not Found', { status: 404 });
|
|
}
|
|
|
|
const updatedFile = await FileModel.update(
|
|
user!.id,
|
|
requestBody.currentPath,
|
|
decodeURIComponent(requestBody.fileName),
|
|
requestBody.contents || '',
|
|
);
|
|
|
|
const responseBody: ResponseBody = { success: updatedFile };
|
|
|
|
return new Response(JSON.stringify(responseBody));
|
|
}
|
|
|
|
export default page({
|
|
post,
|
|
accessMode: 'user',
|
|
});
|