This commit is contained in:
2026-02-23 09:02:34 +00:00
parent 7298ee72aa
commit c3c905907b
9 changed files with 263 additions and 13 deletions
+33
View File
@@ -0,0 +1,33 @@
import { mkdir } from 'node:fs/promises';
import { dirname } from 'node:path';
import { createRouter } from '../../create-router';
import { getUserDockFile } from '@@/data-path';
const ensureDir = (filePath: string) => mkdir(dirname(filePath), { recursive: true });
export const dockRouter = createRouter();
// GET / — return dock.json, or null if it doesn't exist (frontend uses defaults)
dockRouter.get('/', async (ctx) => {
const email = ctx.get('user').email;
const filePath = getUserDockFile(email);
const file = Bun.file(filePath);
if (await file.exists()) {
const data = await file.json();
return ctx.json(data);
}
return ctx.json(null);
});
// PUT / — full replacement of dock paths array
dockRouter.put('/', async (ctx) => {
const email = ctx.get('user').email;
const body = ctx.get('body');
const filePath = getUserDockFile(email);
await ensureDir(filePath);
await Bun.write(filePath, JSON.stringify(body, null, 2));
return ctx.json(body);
});