Skip to content

Commit

Permalink
0609 7:35
Browse files Browse the repository at this point in the history
  • Loading branch information
chourmovs committed Sep 6, 2024
1 parent 51b30d2 commit 40e4717
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
10 changes: 7 additions & 3 deletions webapp/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ app.get('/mpc-update', async (req, res) => {
}
});

// Route SSE pour lancer "blissify init"
app.get('/start-analysis', (req, res) => {
const command = 'blissify init /mnt/Musique';
const analysisProcess = spawn('sh', ['-c', command]);
Expand All @@ -85,15 +86,17 @@ app.get('/start-analysis', (req, res) => {
res.setHeader('Content-Type', 'text/event-stream');
res.setHeader('Cache-Control', 'no-cache');
res.setHeader('Connection', 'keep-alive');
res.flushHeaders();
res.flushHeaders(); // Forcer l'envoi des headers

// Diffuser la sortie en temps réel via SSE
analysisProcess.stdout.on('data', (data) => {
res.write(`data: ${data.toString()}\n\n`);
res.flush(); // Vidage immédiat après chaque ligne envoyée
});

analysisProcess.stderr.on('data', (data) => {
res.write(`data: ${data.toString()}\n\n`);
res.flush(); // Vidage immédiat après chaque ligne d'erreur
});

analysisProcess.on('close', (code) => {
Expand All @@ -102,9 +105,10 @@ app.get('/start-analysis', (req, res) => {
} else {
res.write(`data: Blissify init exécuté avec succès\n\n`);
}
res.end(); // Fermer la connexion après la fin du processus
res.flush(); // Forcer l'envoi final
res.end(); // Terminer la connexion après l'exécution
});
});
});

// Blissify update
app.get('/blissify-update', async (req, res) => {
Expand Down
9 changes: 5 additions & 4 deletions webapp/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@ <h1>Gestion du NAS et des analyses</h1>
});

// Trigger blissify init
document.getElementById('blissify-init-button').addEventListener('click', function() {
document.getElementById('blissify-init-button').addEventListener('click', function () {
const eventSource = new EventSource('/start-analysis');

eventSource.onmessage = function(event) {
eventSource.onmessage = function (event) {
// Ajouter le nouveau contenu sans écraser l'ancien
document.getElementById('console-output').innerText += event.data + '\n';
};

eventSource.onerror = function(event) {
document.getElementById('console-output').innerText += `Erreur : ${event.data}`;
eventSource.onerror = function (event) {
document.getElementById('console-output').innerText += `Erreur : ${event.data}\n`;
eventSource.close(); // Fermer la connexion SSE en cas d'erreur
};
});
Expand Down

0 comments on commit 40e4717

Please sign in to comment.