rowboat/apps/rowboatx/app/api/rowboat/run/route.ts
tusharmagar 5df3b1b524 Refactor RowboatX configuration and enhance editor features
- Updated `next.config.ts` to scope Turbopack to the app's directory.
- Modified `package.json` and `package-lock.json` to include new dependencies for Tiptap and markdown processing.
- Removed deprecated chat API and added new agent and config routes for file management.
- Introduced `JsonEditor` and `MarkdownViewer` components for improved content editing and display.
- Enhanced `TiptapMarkdownEditor` with additional toolbar options and markdown parsing capabilities.
- Updated layout and page components to integrate new editors and improve user experience.
2025-12-22 09:14:09 +05:30

46 lines
1.4 KiB
TypeScript

import { NextRequest } from "next/server";
import os from "os";
import path from "path";
import { promises as fs } from "fs";
const ROWBOAT_ROOT = path.join(os.homedir(), ".rowboat", "runs");
function resolveRunPath(fileParam: string): { target: string; relative: string } {
const normalized = path.normalize(fileParam).replace(/^(\.\.(\/|\\|$))+/, "");
const target = path.join(ROWBOAT_ROOT, normalized);
if (!target.startsWith(ROWBOAT_ROOT)) {
throw new Error("Invalid path");
}
return { target, relative: normalized };
}
export async function GET(req: NextRequest) {
const fileParam = req.nextUrl.searchParams.get("file");
if (!fileParam) {
return Response.json({ error: "file param required" }, { status: 400 });
}
try {
const { target, relative } = resolveRunPath(fileParam);
const content = await fs.readFile(target, "utf8");
let parsed: unknown = null;
try {
parsed = JSON.parse(content);
} catch {
parsed = null;
}
return Response.json({ file: relative, parsed, raw: content });
} catch (error: unknown) {
if (error instanceof Error && error.message === "Invalid path") {
return Response.json(
{ error: "Invalid file path" },
{ status: 400 }
);
}
console.error("Failed to read run file", error);
return Response.json(
{ error: "Failed to read run file" },
{ status: 500 }
);
}
}