Code editor and widget

This commit is contained in:
2026-02-17 23:48:46 +00:00
parent d3f94e45ea
commit 030cf9fbd3
18 changed files with 871 additions and 9 deletions
+17
View File
@@ -79,6 +79,23 @@ router.get('/read', async (ctx) => {
return ctx.json({ content, size: s.size });
});
// Write file contents
router.post('/write', async (ctx) => {
const user = ctx.get('user');
const rootDir = getRootDir(user, ctx.req.query('root') ?? undefined);
const { path, content } = ctx.get('body') as { path: string; content: string };
if (!path) throw errors.BAD_REQUEST('path is required');
if (typeof content !== 'string') throw errors.BAD_REQUEST('content must be a string');
const MAX_SIZE = 5 * 1024 * 1024; // 5 MB
if (new TextEncoder().encode(content).length > MAX_SIZE) throw errors.BAD_REQUEST('Content too large (max 5 MB)');
const absPath = resolveUserPath(rootDir, path);
await mkdir(dirname(absPath), { recursive: true });
await Bun.write(absPath, content);
return ctx.json({ ok: true });
});
// Create directory
router.post('/mkdir', async (ctx) => {
const user = ctx.get('user');