feat(documents): renderização real de PDF via Chromium headless
Substitui a geração de PDF simulada (pdf_s3_key/pdf_sha256/pdf_size_bytes sempre nulos) por Chromium real (Playwright), portado do chromiumPdfRenderer.js do legado: SSRF impossível por construção (setContent + bloqueio de toda requisição de rede da página), browser único reaproveitado com relançamento automático, semáforo de concorrência + timeout duro. Infra: MinIO (compose.yaml, primeiro consumidor real do adapter S3) e instalação condicional do Chromium só na imagem da API (Dockerfile.node). DocumentsService.createGeneration agora renderiza, faz upload e persiste hash/tamanho de verdade; novo endpoint de download GET /v1/documents/generations/:id/pdf. Verificado ao vivo através do container real: PDF gerado, baixado, e SHA-256 conferido byte a byte contra o valor persistido no Postgres. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BcWWuKfykGtUweXmHD6cKx
This commit is contained in:
@@ -390,9 +390,12 @@ export interface CreateGenerationInput {
|
||||
renderContext: Record<string, unknown>;
|
||||
renderedHtml: string;
|
||||
generatedBy?: string | null;
|
||||
pdfS3Key?: string | null;
|
||||
pdfSha256?: string | null;
|
||||
pdfSizeBytes?: number | null;
|
||||
}
|
||||
|
||||
async function findFinalGeneration(
|
||||
export async function findFinalGeneration(
|
||||
templateVersionId: string,
|
||||
source: { clientRegistrationId?: string | null; resellerId?: string | null },
|
||||
): Promise<DocumentGeneration | null> {
|
||||
@@ -418,8 +421,8 @@ async function insertGeneration(input: CreateGenerationInput): Promise<DocumentG
|
||||
const { rows } = await query<DocumentGeneration>(
|
||||
`INSERT INTO document_generations
|
||||
(template_id, template_version_id, client_registration_id, reseller_id,
|
||||
render_context, rendered_html, status, generated_by)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, 'final', $7)
|
||||
render_context, rendered_html, pdf_s3_key, pdf_sha256, pdf_size_bytes, status, generated_by)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, 'final', $10)
|
||||
RETURNING *`,
|
||||
[
|
||||
input.templateId,
|
||||
@@ -428,6 +431,9 @@ async function insertGeneration(input: CreateGenerationInput): Promise<DocumentG
|
||||
input.resellerId ?? null,
|
||||
JSON.stringify(input.renderContext),
|
||||
input.renderedHtml,
|
||||
input.pdfS3Key ?? null,
|
||||
input.pdfSha256 ?? null,
|
||||
input.pdfSizeBytes ?? null,
|
||||
input.generatedBy ?? null,
|
||||
],
|
||||
);
|
||||
@@ -471,6 +477,11 @@ export interface ListGenerationsFilter {
|
||||
resellerId?: string;
|
||||
}
|
||||
|
||||
export async function getGenerationById(id: string): Promise<DocumentGeneration | null> {
|
||||
const { rows } = await query<DocumentGeneration>("SELECT * FROM document_generations WHERE id = $1", [id]);
|
||||
return rows[0] ?? null;
|
||||
}
|
||||
|
||||
export async function listGenerations(filter: ListGenerationsFilter = {}): Promise<DocumentGeneration[]> {
|
||||
const conditions: string[] = [];
|
||||
const params: unknown[] = [];
|
||||
|
||||
Reference in New Issue
Block a user