mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-24 07:28:19 +02:00
Merge pull request #339 from R0m1k3/1.1
Update how the system sends data to external services
This commit is contained in:
4 files changed
+33
-30
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 146 KiB |
@@ -95,6 +95,26 @@ export default function Sidebar() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Récupérer l'URL webhook configurée
|
||||||
|
let webhookUrl = '';
|
||||||
|
try {
|
||||||
|
const configResponse = await fetch('/api/webhook-bap-config', {
|
||||||
|
credentials: 'include'
|
||||||
|
});
|
||||||
|
|
||||||
|
if (configResponse.ok) {
|
||||||
|
const config = await configResponse.json();
|
||||||
|
webhookUrl = config?.webhookUrl;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Impossible de récupérer la config webhook, utilisation URL par défaut');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Utiliser une URL par défaut si pas de configuration
|
||||||
|
if (!webhookUrl) {
|
||||||
|
webhookUrl = "https://workflow.ffnancy.fr/webhook-test/a3d03176-b72f-412d-8fb9-f920b9fbab4d";
|
||||||
|
}
|
||||||
|
|
||||||
// Fermer le modal de sélection et ouvrir le modal d'attente
|
// Fermer le modal de sélection et ouvrir le modal d'attente
|
||||||
setShowBapModal(false);
|
setShowBapModal(false);
|
||||||
setShowWaitingModal(true);
|
setShowWaitingModal(true);
|
||||||
@@ -102,48 +122,30 @@ export default function Sidebar() {
|
|||||||
startProcessingTimer();
|
startProcessingTimer();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Convertir le fichier en base64
|
// Utiliser FormData comme le système de rapprochement qui fonctionne
|
||||||
const pdfBase64 = await new Promise<string>((resolve, reject) => {
|
const formData = new FormData();
|
||||||
const reader = new FileReader();
|
formData.append('file', selectedFile);
|
||||||
reader.onload = () => {
|
formData.append('recipient', selectedRecipient);
|
||||||
const result = reader.result as string;
|
formData.append('type', 'BAP');
|
||||||
// Enlever le préfixe "data:application/pdf;base64,"
|
formData.append('fileName', selectedFile.name);
|
||||||
const base64 = result.split(',')[1];
|
|
||||||
resolve(base64);
|
|
||||||
};
|
|
||||||
reader.onerror = () => reject(new Error('Erreur lors de la lecture du fichier'));
|
|
||||||
reader.readAsDataURL(selectedFile);
|
|
||||||
});
|
|
||||||
|
|
||||||
const requestBody = {
|
|
||||||
pdfBase64,
|
|
||||||
fileName: selectedFile.name,
|
|
||||||
recipient: selectedRecipient
|
|
||||||
};
|
|
||||||
|
|
||||||
// Créer un AbortController pour gérer le timeout
|
// Créer un AbortController pour gérer le timeout
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
const timeoutId = setTimeout(() => controller.abort(), 60000); // 60 secondes
|
const timeoutId = setTimeout(() => controller.abort(), 60000); // 60 secondes
|
||||||
|
|
||||||
const response = await fetch('/api/bap/send-webhook', {
|
// Envoyer directement au webhook (comme le rapprochement)
|
||||||
|
const response = await fetch(webhookUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
body: formData,
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
body: JSON.stringify(requestBody),
|
|
||||||
signal: controller.signal,
|
signal: controller.signal,
|
||||||
credentials: 'include'
|
|
||||||
});
|
});
|
||||||
|
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errorData = await response.json();
|
throw new Error(`Erreur ${response.status}: ${response.statusText}`);
|
||||||
throw new Error(errorData.error || `Erreur ${response.status}: ${response.statusText}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await response.json();
|
|
||||||
|
|
||||||
handleCloseWaitingModal();
|
handleCloseWaitingModal();
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
|
|||||||
+2
-1
@@ -40,8 +40,9 @@ import {
|
|||||||
insertSavTicketHistorySchema,
|
insertSavTicketHistorySchema,
|
||||||
insertWeatherDataSchema,
|
insertWeatherDataSchema,
|
||||||
insertWeatherSettingsSchema,
|
insertWeatherSettingsSchema,
|
||||||
|
insertWebhookBapConfigSchema,
|
||||||
users, groups, userGroups, suppliers, orders, deliveries, publicities, publicityParticipations,
|
users, groups, userGroups, suppliers, orders, deliveries, publicities, publicityParticipations,
|
||||||
customerOrders, nocodbConfig, dlcProducts, tasks, invoiceVerificationCache, dashboardMessages
|
customerOrders, nocodbConfig, dlcProducts, tasks, invoiceVerificationCache, dashboardMessages, webhookBapConfig
|
||||||
} from "@shared/schema";
|
} from "@shared/schema";
|
||||||
import { hasPermission } from "@shared/permissions";
|
import { hasPermission } from "@shared/permissions";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|||||||
+1
-1
@@ -3896,7 +3896,7 @@ export class MemStorage implements IStorage {
|
|||||||
return {
|
return {
|
||||||
id: 1,
|
id: 1,
|
||||||
name: "Configuration BAP",
|
name: "Configuration BAP",
|
||||||
webhookUrl: "https://workflow.ffnancy.fr/webhook/a3d03176-b72f-412d-8fb9-f920b9fbab4d",
|
webhookUrl: "https://workflow.ffnancy.fr/webhook-test/a3d03176-b72f-412d-8fb9-f920b9fbab4d",
|
||||||
description: "Configuration par défaut pour développement",
|
description: "Configuration par défaut pour développement",
|
||||||
isActive: true,
|
isActive: true,
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
|
|||||||
Reference in new issue
Block a user