mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-21 05:58:23 +02:00
Update webhook integration to use JSON for sending PDF data
Replaces multipart form data handling with JSON payload for the webhook API call, sending PDF content as a base64 encoded string. This change also removes the `busboy` dependency. Replit-Commit-Author: Agent Replit-Commit-Session-Id: cfbfe47c-0c9a-4ebf-8a41-2937407eccff Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/cfbfe47c-0c9a-4ebf-8a41-2937407eccff/WbfLPZt
This commit is contained in:
1 parent
caee73e16b
commit
bd6b25e608
6 files changed
+235
-89
No files matched your search
+17
-52
@@ -49,7 +49,6 @@ import { eq, desc, or, isNull } from "drizzle-orm";
|
||||
import { invoiceVerificationService } from "./invoiceVerification";
|
||||
import { backupService } from "./backupService";
|
||||
import { weatherService } from "./weatherService.js";
|
||||
import Busboy from 'busboy';
|
||||
import fetch from "node-fetch";
|
||||
|
||||
export async function registerRoutes(app: Express): Promise<Server> {
|
||||
@@ -78,69 +77,35 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
return res.status(403).json({ error: 'Accès refusé - Admin uniquement' });
|
||||
}
|
||||
|
||||
// Parser le multipart/form-data avec busboy
|
||||
const busboy = Busboy({ headers: req.headers });
|
||||
let fileBuffer: Buffer | null = null;
|
||||
let fileName = '';
|
||||
let recipient = '';
|
||||
let mimeType = '';
|
||||
|
||||
const parsePromise = new Promise<void>((resolve, reject) => {
|
||||
busboy.on('file', (fieldname, file, info) => {
|
||||
const { filename, mimeType: fileMimeType } = info;
|
||||
|
||||
if (fieldname === 'pdf') {
|
||||
fileName = filename;
|
||||
mimeType = fileMimeType;
|
||||
|
||||
const chunks: Buffer[] = [];
|
||||
file.on('data', (chunk) => {
|
||||
chunks.push(chunk);
|
||||
});
|
||||
|
||||
file.on('end', () => {
|
||||
fileBuffer = Buffer.concat(chunks);
|
||||
});
|
||||
} else {
|
||||
file.resume(); // Ignorer les autres fichiers
|
||||
}
|
||||
});
|
||||
|
||||
busboy.on('field', (fieldname, val) => {
|
||||
if (fieldname === 'recipient') {
|
||||
recipient = val;
|
||||
}
|
||||
});
|
||||
|
||||
busboy.on('finish', () => {
|
||||
resolve();
|
||||
});
|
||||
|
||||
busboy.on('error', (err) => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
|
||||
req.pipe(busboy);
|
||||
await parsePromise;
|
||||
// Récupérer les données JSON du body
|
||||
const { pdfBase64, fileName, recipient } = req.body;
|
||||
|
||||
// Valider les données
|
||||
if (!fileBuffer) {
|
||||
return res.status(400).json({ error: 'Aucun fichier PDF fourni' });
|
||||
if (!pdfBase64 || !fileName || !recipient) {
|
||||
return res.status(400).json({ error: 'Données manquantes: pdfBase64, fileName ou recipient' });
|
||||
}
|
||||
|
||||
if (mimeType !== 'application/pdf') {
|
||||
if (!['Prissela', 'Célia'].includes(recipient)) {
|
||||
return res.status(400).json({ error: 'Destinataire invalide' });
|
||||
}
|
||||
|
||||
// Vérifier l'extension PDF
|
||||
if (!fileName.toLowerCase().endsWith('.pdf')) {
|
||||
return res.status(400).json({ error: 'Le fichier doit être un PDF' });
|
||||
}
|
||||
|
||||
if (!recipient || !['Prissela', 'Célia'].includes(recipient)) {
|
||||
return res.status(400).json({ error: 'Destinataire invalide' });
|
||||
// Décoder le base64 en buffer
|
||||
let fileBuffer: Buffer;
|
||||
try {
|
||||
fileBuffer = Buffer.from(pdfBase64, 'base64');
|
||||
} catch (error) {
|
||||
return res.status(400).json({ error: 'Format base64 invalide' });
|
||||
}
|
||||
|
||||
console.log('📤 BAP: Envoi webhook n8n', {
|
||||
recipient,
|
||||
fileName,
|
||||
fileSize: fileBuffer?.length || 0,
|
||||
fileSize: fileBuffer.length,
|
||||
userId: user.id
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user