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:
@@ -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",
|
||||
|
||||
@@ -656,6 +656,7 @@ export const appRouter = router({
|
||||
|
||||
return {
|
||||
success: true,
|
||||
invoiceId: input.id,
|
||||
validatedAt,
|
||||
pdfUrl,
|
||||
exportPath,
|
||||
|
||||
Reference in New Issue
Block a user