Checkpoint: Ajout du bouton de téléchargement direct du PDF annoté BAP : route Express /api/download-bap/:filename avec Content-Disposition attachment, bouton Télécharger dans InvoicesBAP (apparaît après validation), boutons Voir + Télécharger dans l'Historique BAP. Correction du layout PDF (2 colonnes) également incluse.

This commit is contained in:
Manus
2026-04-12 10:05:02 -04:00
parent 3cbd705249
commit 9d71f1e34a
4 changed files with 87 additions and 15 deletions

View File

@@ -2,6 +2,8 @@ import "dotenv/config";
import express from "express";
import { createServer } from "http";
import net from "net";
import path from "path";
import fs from "fs";
import { createExpressMiddleware } from "@trpc/server/adapters/express";
import { registerOAuthRoutes } from "./oauth";
import { appRouter } from "../routers";
@@ -38,6 +40,19 @@ async function startServer() {
// Serve local storage files
app.use("/storage", express.static("storage"));
// Route de téléchargement forcé du PDF annoté BAP
app.get("/api/download-bap/:filename", (req, res) => {
const filename = path.basename(req.params.filename); // sécurité : pas de path traversal
const storagePath = path.resolve("storage", filename);
if (!fs.existsSync(storagePath)) {
res.status(404).json({ error: "Fichier introuvable" });
return;
}
res.setHeader("Content-Disposition", `attachment; filename="${filename}"`);
res.setHeader("Content-Type", "application/pdf");
res.sendFile(storagePath);
});
// tRPC API
app.use(
"/api/trpc",