Skip to content

Commit

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

// Start analysis (assuming blissify is command)
app.get('/start-analysis', async (req, res) => {
try {
const analysisProcess = spawn('blissify', ['init', '/mnt/Musique']);
let output = '';

analysisProcess.stdout.on('data', (data) => {
output += data.toString();

console.log(`Analysis stdout: ${data}`);
app.get('/start-analysis', (req, res) => {
const command = 'blissify init /mnt/Musique';
const analysisProcess = spawn('sh', ['-c', command]);

// SSE headers
res.setHeader('Content-Type', 'text/event-stream');
res.setHeader('Cache-Control', 'no-cache');
res.setHeader('Connection', 'keep-alive');
res.flushHeaders();

// Diffuser la sortie en temps réel via SSE
analysisProcess.stdout.on('data', (data) => {
res.write(`data: ${data.toString()}\n\n`);
});

analysisProcess.stderr.on('data', (data) => {
output += data.toString();
console.error(`Analysis stderr: ${data}`);
res.write(`data: ${data.toString()}\n\n`);
});

const exitPromise = new Promise((resolve, reject) => {
analysisProcess.on('close', (code) => {
if (code === 0) {
resolve();

analysisProcess.on('close', (code) => {
if (code !== 0) {
res.write(`data: Erreur lors de l'exécution de blissify init (code ${code})\n\n`);
} else {
reject(new Error(`Analysis process exited with code ${code}`));
res.write(`data: Blissify init exécuté avec succès\n\n`);
}
});

analysisProcess.on('error', (err) => {
reject(err);
});
res.end(); // Fermer la connexion après la fin du processus
});

await exitPromise;

res.send(`Analysis started successfully: ${output}`);
} catch (error) {
console.error('Analysis start command failed:', error);
res.status(500).send('Error starting analysis');
}
});
});

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

// Trigger blissify init
document.getElementById('blissify-init-button').addEventListener('click', function () {
fetch('/start-analysis')
.then(response => response.text())
.then(data => {
document.getElementById('console-output').innerText += data;
}).catch(error => {
console.error('Error:', error);
});
document.getElementById('blissify-init-button').addEventListener('click', function() {
const eventSource = new EventSource('/start-analysis');

eventSource.onmessage = function(event) {
document.getElementById('console-output').innerText += event.data + '\n';
};

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

// Trigger blissify update
Expand Down

0 comments on commit 51b30d2

Please sign in to comment.