ffezef
This commit is contained in:
parent
8f00705265
commit
1e3929c484
@ -58,20 +58,36 @@
|
|||||||
<script>
|
<script>
|
||||||
// Vérification du QR code et statut de connexion
|
// Vérification du QR code et statut de connexion
|
||||||
async function checkQR() {
|
async function checkQR() {
|
||||||
try {
|
try {
|
||||||
const res = await fetch('/api/qrcode');
|
const res = await fetch('/api/qrcode');
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
const qrContainer = document.getElementById('qrcode');
|
console.log('Réponse /api/qrcode :', data);
|
||||||
if (data.connected) {
|
|
||||||
qrContainer.innerHTML = '✅ Connecté à WhatsApp !';
|
const qrContainer = document.getElementById('qrcode');
|
||||||
} else if (data.qr) {
|
if (data.connected) {
|
||||||
|
qrContainer.innerHTML = '✅ Connecté à WhatsApp !';
|
||||||
|
} else if (data.qr) {
|
||||||
|
// Si data.qr est une chaîne (Data-URL)
|
||||||
|
if (typeof data.qr === 'string') {
|
||||||
qrContainer.innerHTML = `<img src="${data.qr}" alt="QR Code WhatsApp" width="200" height="200"/>`;
|
qrContainer.innerHTML = `<img src="${data.qr}" alt="QR Code WhatsApp" width="200" height="200"/>`;
|
||||||
|
}
|
||||||
|
// Sinon, si c'est un objet { data: […], mime: 'image/png' }
|
||||||
|
else if (data.qr.data) {
|
||||||
|
const uint8Array = new Uint8Array(data.qr.data);
|
||||||
|
const base64 = btoa(String.fromCharCode(...uint8Array));
|
||||||
|
const src = `data:${data.qr.mime};base64,${base64}`;
|
||||||
|
qrContainer.innerHTML = `<img src="${src}" alt="QR Code WhatsApp" width="200" height="200"/>`;
|
||||||
|
} else {
|
||||||
|
qrContainer.textContent = 'QR reçu, mais format non pris en charge.';
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} else {
|
||||||
console.error('Erreur checkQR:', err);
|
qrContainer.textContent = 'Pas encore de QR disponible.';
|
||||||
}
|
}
|
||||||
setTimeout(checkQR, 3000);
|
} catch (err) {
|
||||||
|
console.error('Erreur checkQR:', err);
|
||||||
}
|
}
|
||||||
|
setTimeout(checkQR, 3000);
|
||||||
|
}
|
||||||
checkQR();
|
checkQR();
|
||||||
|
|
||||||
// Envoi du formulaire interactif
|
// Envoi du formulaire interactif
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user