mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-03 08:53:36 +00:00
- Updated 150+ files to import from @automaker/* packages - Server imports now use @automaker/utils, @automaker/platform, @automaker/types, @automaker/model-resolver, @automaker/dependency-resolver, @automaker/git-utils - UI imports now use @automaker/dependency-resolver and @automaker/types - Deleted duplicate dependency-resolver files (222 lines eliminated) - Updated dependency-resolver to use ES modules for Vite compatibility - Added type annotation fix in auto-mode-service.ts - Updated feature-loader to re-export Feature type from @automaker/types - Both server and UI builds successfully verified Phase 1 of server refactoring complete. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
/**
|
|
* POST /read endpoint - Read file
|
|
*/
|
|
|
|
import type { Request, Response } from "express";
|
|
import fs from "fs/promises";
|
|
import { validatePath } from "@automaker/platform";
|
|
import { getErrorMessage, logError } from "../common.js";
|
|
|
|
// Optional files that are expected to not exist in new projects
|
|
// Don't log ENOENT errors for these to reduce noise
|
|
const OPTIONAL_FILES = ["categories.json", "app_spec.txt"];
|
|
|
|
function isOptionalFile(filePath: string): boolean {
|
|
return OPTIONAL_FILES.some((optionalFile) => filePath.endsWith(optionalFile));
|
|
}
|
|
|
|
function isENOENT(error: unknown): boolean {
|
|
return (
|
|
error !== null &&
|
|
typeof error === "object" &&
|
|
"code" in error &&
|
|
error.code === "ENOENT"
|
|
);
|
|
}
|
|
|
|
export function createReadHandler() {
|
|
return async (req: Request, res: Response): Promise<void> => {
|
|
try {
|
|
const { filePath } = req.body as { filePath: string };
|
|
|
|
if (!filePath) {
|
|
res.status(400).json({ success: false, error: "filePath is required" });
|
|
return;
|
|
}
|
|
|
|
const resolvedPath = validatePath(filePath);
|
|
const content = await fs.readFile(resolvedPath, "utf-8");
|
|
|
|
res.json({ success: true, content });
|
|
} catch (error) {
|
|
// Don't log ENOENT errors for optional files (expected to be missing in new projects)
|
|
const shouldLog = !(isENOENT(error) && isOptionalFile(req.body?.filePath || ""));
|
|
if (shouldLog) {
|
|
logError(error, "Read file failed");
|
|
}
|
|
res.status(500).json({ success: false, error: getErrorMessage(error) });
|
|
}
|
|
};
|
|
}
|