fixes
Build and Push Docker Image / build (push) Successful in 1m6s

This commit is contained in:
jason
2026-04-21 20:59:55 -05:00
parent bb452a59ae
commit bc3b78aa33
17 changed files with 534 additions and 40 deletions
+38 -4
View File
@@ -1,6 +1,7 @@
import { type NextRequest, NextResponse } from "next/server";
import { prisma } from "@/lib/prisma";
import { errorResponse, requireRole, ApiError } from "@/lib/api";
import { readFileBytes } from "@/lib/files";
import {
renderPartTravelers,
type OperationCardData,
@@ -24,10 +25,15 @@ export async function GET(_req: NextRequest, ctx: { params: Promise<{ id: string
where: { id },
include: {
assembly: {
include: { project: { select: { code: true, name: true } } },
include: {
project: { select: { code: true, name: true } },
drawingFile: { select: { path: true, originalName: true } },
},
},
stepFile: { select: { originalName: true, sizeBytes: true, sha256: true } },
drawingFile: { select: { originalName: true, sizeBytes: true, sha256: true } },
drawingFile: {
select: { originalName: true, sizeBytes: true, sha256: true, path: true },
},
cutFile: { select: { originalName: true, sizeBytes: true, sha256: true } },
operations: {
orderBy: { sequence: "asc" },
@@ -42,7 +48,11 @@ export async function GET(_req: NextRequest, ctx: { params: Promise<{ id: string
}
const project = part.assembly.project;
const assembly = { code: part.assembly.code, name: part.assembly.name };
const assembly = {
code: part.assembly.code,
name: part.assembly.name,
qty: part.assembly.qty,
};
const partHeader = {
code: part.code,
name: part.name,
@@ -50,6 +60,14 @@ export async function GET(_req: NextRequest, ctx: { params: Promise<{ id: string
qty: part.qty,
};
// Pull drawing PDFs off disk so pdf-lib can inline them behind the cover /
// op cards. Missing / unreadable files are logged and skipped — the
// traveler still prints without them rather than 500ing.
const drawingPdfBytes = await tryReadPdf(part.drawingFile?.path ?? null);
const assemblyDrawingPdfBytes = await tryReadPdf(
part.assembly.drawingFile?.path ?? null,
);
const cover: PartCoverData = {
project,
assembly,
@@ -88,7 +106,12 @@ export async function GET(_req: NextRequest, ctx: { params: Promise<{ id: string
},
}));
const pdf = await renderPartTravelers({ cover, cards });
const pdf = await renderPartTravelers({
cover,
cards,
drawingPdfBytes,
assemblyDrawingPdfBytes,
});
const safeName = `${part.code}-travelers.pdf`.replace(/[^A-Za-z0-9._-]/g, "_");
return new NextResponse(pdf as unknown as BodyInit, {
@@ -103,3 +126,14 @@ export async function GET(_req: NextRequest, ctx: { params: Promise<{ id: string
return errorResponse(err);
}
}
async function tryReadPdf(path: string | null): Promise<Uint8Array | null> {
if (!path) return null;
try {
const buf = await readFileBytes(path);
return new Uint8Array(buf);
} catch (err) {
console.warn("[travelers.pdf] could not read drawing file", { path, err });
return null;
}
}