feat(camera): Améliorer la gestion de l'arrêt de la caméra en ajoutant la recherche de projets en cours d'arrêt et en mettant à jour les statuts appropriés
All checks were successful
SSH Backend Deploy / ssh-deploy (push) Successful in 10s
All checks were successful
SSH Backend Deploy / ssh-deploy (push) Successful in 10s
This commit is contained in:
@@ -73,18 +73,26 @@ class CameraController {
|
||||
* Initie l'arrêt de la procédure de capture
|
||||
*/
|
||||
static stopProcedure = asyncHandler(async (req, res) => {
|
||||
const { project_id } = req.body;
|
||||
|
||||
try {
|
||||
// Trouve le projet actuellement en cours de capture
|
||||
const currentProject = await Project.findCurrentRenderingProject();
|
||||
|
||||
if (!currentProject) {
|
||||
return sendError('Aucun projet en cours de capture trouvé', res, null, 404);
|
||||
}
|
||||
|
||||
// Met à jour le statut du projet en cours d'arrêt
|
||||
await Project.updateProject(project_id, { status: config.projectStatus.stopping });
|
||||
await Project.updateProjectStatus(currentProject.id, config.projectStatus.stopping);
|
||||
|
||||
// Marque le drapeau d'arrêt
|
||||
await Camera.updateCamera(1, { stop_flag: true });
|
||||
|
||||
console.log('[CAMERA] Arrêt de la caméra demandé, en attente de confirmation...');
|
||||
console.log(`[CAMERA] Arrêt de la caméra demandé pour le projet ${currentProject.id}, en attente de confirmation...`);
|
||||
|
||||
res.json({ message: 'Procédure d\'arrêt de la caméra initiée avec succès' });
|
||||
res.json({
|
||||
message: 'Procédure d\'arrêt de la caméra initiée avec succès',
|
||||
project_id: currentProject.id
|
||||
});
|
||||
} catch (error) {
|
||||
sendError('Erreur lors de l\'arrêt de la procédure de capture', res, error, 500);
|
||||
}
|
||||
@@ -105,19 +113,39 @@ class CameraController {
|
||||
|
||||
await Camera.updateCamera(1, newSettings);
|
||||
|
||||
// Réinitialise le statut du projet en cours
|
||||
const currentProject = await Project.findCurrentRenderingProject();
|
||||
// Recherche le projet en cours d'arrêt
|
||||
const stoppingProject = await Project.findStoppingProject();
|
||||
|
||||
if (currentProject) {
|
||||
await Project.updateProject(currentProject.id, { status: config.projectStatus.idle});
|
||||
console.log(`[CAMERA] Projet : ${currentProject.id} arrêté.`);
|
||||
if (stoppingProject) {
|
||||
// Mettre à jour le statut du projet en cours d'arrêt vers idle
|
||||
await Project.updateProjectStatus(stoppingProject.id, config.projectStatus.idle);
|
||||
console.log(`[CAMERA] Projet : ${stoppingProject.id} arrêté avec succès.`);
|
||||
|
||||
res.json({
|
||||
message: 'Caméra arrêtée avec succès',
|
||||
project_id: stoppingProject.id,
|
||||
status: config.projectStatus.idle
|
||||
});
|
||||
} else {
|
||||
console.log('[CAMERA] Aucun projet à arrêter.');
|
||||
// Vérifier s'il y a un projet en cours de capture qui n'aurait pas été marqué comme stopping
|
||||
const currentProject = await Project.findCurrentRenderingProject();
|
||||
|
||||
if (currentProject) {
|
||||
await Project.updateProjectStatus(currentProject.id, config.projectStatus.idle);
|
||||
console.log(`[CAMERA] Projet : ${currentProject.id} arrêté (était en capture).`);
|
||||
|
||||
res.json({
|
||||
message: 'Caméra arrêtée avec succès (projet était en capture)',
|
||||
project_id: currentProject.id,
|
||||
status: config.projectStatus.idle
|
||||
});
|
||||
} else {
|
||||
console.log('[CAMERA] Aucun projet en cours d\'arrêt ou de capture trouvé.');
|
||||
res.json({ message: 'Caméra arrêtée avec succès mais aucun projet à mettre à jour' });
|
||||
}
|
||||
}
|
||||
|
||||
console.log('[CAMERA] Caméra arrêtée.');
|
||||
|
||||
res.json({ message: 'Caméra arrêtée avec succès' });
|
||||
} catch (error) {
|
||||
sendError('Erreur lors de la confirmation de l\'arrêt de la caméra', res, error, 500);
|
||||
}
|
||||
|
||||
@@ -94,6 +94,16 @@ class Project {
|
||||
const result = await db.query(query);
|
||||
return result.rows[0] || null;
|
||||
});
|
||||
|
||||
/**
|
||||
* Trouve le projet en cours d'arrêt (status = stopping)
|
||||
* @returns {Promise<Object|null>} Projet en cours d'arrêt ou null
|
||||
*/
|
||||
static findStoppingProject = wrapDatabaseOperation(async () => {
|
||||
const query = `SELECT * FROM projects WHERE status = ${config.projectStatus.stopping};`;
|
||||
const result = await db.query(query);
|
||||
return result.rows[0] || null;
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = Project;
|
||||
Reference in New Issue
Block a user