useDock
This commit is contained in:
@@ -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);
|
||||
});
|
||||
@@ -70,3 +70,5 @@ export const getTmpAttachmentsDir = (email: string) => join(DATA_PATH, email, 'c
|
||||
|
||||
export const getAttachmentsDir = (email: string, provider: 'claude' | 'opencode' | 'pi-mono', sessionId: string) =>
|
||||
join(DATA_PATH, email, 'chat_sessions', provider, sessionId, 'attachments');
|
||||
|
||||
export const getUserDockFile = (email: string) => join(DATA_PATH, email, 'dock', 'dock.json');
|
||||
|
||||
@@ -19,6 +19,7 @@ import { taskLogsRouter } from './api/task-logs/task-logs';
|
||||
import { router as fileBrowserRouter } from './api/file-browser/router';
|
||||
import { piRestRouter } from './api/pi/rest';
|
||||
import { devServerRouter, devServerProxyRouter } from './api/dev-server/router';
|
||||
import { dockRouter } from './api/dock/dock';
|
||||
import { CustomError } from './custom-errors';
|
||||
import { userMiddleware, bodyParser } from './_middlewares';
|
||||
|
||||
@@ -59,6 +60,7 @@ protectedRouter.route('/workspaces', workspacesRouter);
|
||||
protectedRouter.route('/task-logs', taskLogsRouter);
|
||||
protectedRouter.route('/file-browser', fileBrowserRouter);
|
||||
protectedRouter.route('/dev-server', devServerRouter);
|
||||
protectedRouter.route('/dock', dockRouter);
|
||||
protectedRouter.route('/', piRestRouter);
|
||||
|
||||
honoServer.route('/api', protectedRouter);
|
||||
|
||||
Reference in New Issue
Block a user