ffezef
This commit is contained in:
parent
8f00705265
commit
1e3929c484
@ -58,20 +58,36 @@
|
||||
<script>
|
||||
// Vérification du QR code et statut de connexion
|
||||
async function checkQR() {
|
||||
try {
|
||||
const res = await fetch('/api/qrcode');
|
||||
const data = await res.json();
|
||||
const qrContainer = document.getElementById('qrcode');
|
||||
if (data.connected) {
|
||||
qrContainer.innerHTML = '✅ Connecté à WhatsApp !';
|
||||
} else if (data.qr) {
|
||||
try {
|
||||
const res = await fetch('/api/qrcode');
|
||||
const data = await res.json();
|
||||
console.log('Réponse /api/qrcode :', data);
|
||||
|
||||
const qrContainer = document.getElementById('qrcode');
|
||||
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"/>`;
|
||||
}
|
||||
// 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) {
|
||||
console.error('Erreur checkQR:', err);
|
||||
} else {
|
||||
qrContainer.textContent = 'Pas encore de QR disponible.';
|
||||
}
|
||||
setTimeout(checkQR, 3000);
|
||||
} catch (err) {
|
||||
console.error('Erreur checkQR:', err);
|
||||
}
|
||||
setTimeout(checkQR, 3000);
|
||||
}
|
||||
checkQR();
|
||||
|
||||
// Envoi du formulaire interactif
|
||||
|
||||
Loading…
Reference in New Issue
Block a user