Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Thumbs.db
*.log
logs/
coverage/
coverage.xml
*.coverage
htmlcov/
.coverage.*
Expand Down Expand Up @@ -98,6 +99,7 @@ kubeconfig-local
.venv-openconstructionerp/
03-frontend/.architoken/
data/
cache.db
04-backend/config/local.*
*.bak-*
*.broken-*
65 changes: 65 additions & 0 deletions 03-frontend/app/api/local-files/[fileId]/cad-derivative/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// app/api/local-files/[fileId]/cad-derivative/route.ts - Native CAD derivative endpoint
// License: Apache-2.0

import { NextResponse } from 'next/server';
import {
buildCadDerivativeManifest,
CadDerivativeError,
readCadDerivativeBytes,
type CadDerivativeFormat,
} from '@/lib/cad-derivative-server';

export const runtime = 'nodejs';

export async function GET(
request: Request,
{ params }: { params: Promise<{ fileId: string }> },
) {
const { fileId } = await params;
const url = new URL(request.url);
const format = normalizeFormat(url.searchParams.get('format'));
const sheet = url.searchParams.get('sheet');

try {
if (format === 'manifest') {
return NextResponse.json(await buildCadDerivativeManifest(fileId));
}

const derivative = await readCadDerivativeBytes(fileId, format, sheet);
const body = new Uint8Array(derivative.bytes.byteLength);
body.set(derivative.bytes);
return new Response(body, {
headers: {
'content-type': derivative.mediaType,
'content-length': String(derivative.bytes.byteLength),
'content-disposition': `inline; filename*=UTF-8''${encodeURIComponent(derivative.fileName)}`,
'x-architoken-cad-engine': derivative.engine,
},
});
} catch (error) {
if (error instanceof CadDerivativeError) {
return NextResponse.json(
{
error: error.code,
message: error.message,
...error.details,
},
{ status: error.status },
);
}
return NextResponse.json(
{
error: 'cad_derivative_failed',
message: error instanceof Error ? error.message : String(error),
},
{ status: 500 },
);
}
}

function normalizeFormat(value: string | null): CadDerivativeFormat {
if (value === 'dxf' || value === 'pdf' || value === 'manifest') {
return value;
}
return 'manifest';
}
Loading