mirror of
https://github.com/Heretek-AI/ompweb.git
synced 2026-11-10 05:41:34 -10:00
- lib/api-utils: resolveSessionPathOr404 collapses the resolveSessionPath +
'Session not found' guard repeated across 10 session routes; apiErrorResponse
replaces the ~20 { error: String(error) }, { status: 500 } one-liners.
- components/MarkdownCode: the renderer duplicated verbatim between
MarkdownBody and FileViewer (mermaid/CodeBlock dispatch + inline code) is now
one factory; the defaultPreview/isStreaming/inline-class deltas are options.
- upload loop error handling deduped into a local recordError.
20 lines
854 B
TypeScript
20 lines
854 B
TypeScript
import { NextResponse } from "next/server";
|
|
import { resolveSessionPath } from "./session-reader";
|
|
|
|
const SESSION_NOT_FOUND = { error: "Session not found", code: "session_not_found" } as const;
|
|
|
|
/** Resolve a session id to its file path, or a 404 JSON response. Replaces the
|
|
* repeated `resolveSessionPath(id)` + "Session not found" guard across routes. */
|
|
export async function resolveSessionPathOr404(
|
|
id: string,
|
|
): Promise<{ filePath: string } | { response: NextResponse }> {
|
|
const filePath = await resolveSessionPath(id);
|
|
if (!filePath) return { response: NextResponse.json(SESSION_NOT_FOUND, { status: 404 }) };
|
|
return { filePath };
|
|
}
|
|
|
|
/** Uniform JSON error body used by most API routes. */
|
|
export function apiErrorResponse(error: unknown, status = 500): NextResponse {
|
|
return NextResponse.json({ error: String(error) }, { status });
|
|
}
|