Ajout de la gestion des routes pour le système de capture, mise à jour des chemins de fichiers et amélioration de la logique de gestion des mesures et vidéos.
This commit is contained in:
@@ -38,7 +38,7 @@ async function checkAndRemoveInvalidEntries() {
|
||||
|
||||
// Run the check periodically
|
||||
console.log('[INFO] Activation du FileWatcher pour surveiller les fichiers invalides...')
|
||||
setInterval(checkAndRemoveInvalidEntries, 10000); // Every 10 seconds
|
||||
setInterval(checkAndRemoveInvalidEntries, 1000); // Every 10 seconds
|
||||
|
||||
// Initial run
|
||||
checkAndRemoveInvalidEntries();
|
||||
@@ -1,5 +1,6 @@
|
||||
const fs = require('fs').promises;
|
||||
const path = require('path');
|
||||
const { Buffer } = require('buffer');
|
||||
const PROJECTS_DIR = path.join('.');
|
||||
const database_manager = require('../database/database_manager.js');
|
||||
|
||||
@@ -62,7 +63,8 @@ async function scanAllImages(dir = 'storage') {
|
||||
}
|
||||
|
||||
async function saveFile(filePath, content) {
|
||||
let Buffer=Buffer.from(content, 'base64');
|
||||
const dir = path.dirname(filePath);
|
||||
await fs.mkdir(dir, { recursive: true });
|
||||
if (Buffer.isBuffer(content)) {
|
||||
await fs.writeFile(filePath, content);
|
||||
} else {
|
||||
@@ -101,7 +103,7 @@ async function handleFileOperation(operation, ...args) {
|
||||
|
||||
const project = {
|
||||
createProjectDirectory: async function (projectId) {
|
||||
const projectPath = `${projectId}`;
|
||||
const projectPath = path.join(PROJECTS_DIR, 'storage', `${projectId}`);
|
||||
await handleFileOperation(createFolder, projectPath);
|
||||
await handleFileOperation(createFolder, `${projectPath}/images`);
|
||||
await handleFileOperation(createFolder, `${projectPath}/videos`);
|
||||
@@ -109,7 +111,7 @@ const project = {
|
||||
},
|
||||
|
||||
deleteProjectDirectory: async function (projectId) {
|
||||
const projectPath = `${projectId}`;
|
||||
const projectPath = path.join(PROJECTS_DIR, 'storage', `${projectId}`);
|
||||
await handleFileOperation(deleteFolder, projectPath);
|
||||
console.log("[FILE] deleteProjectDirectory : " + projectPath);
|
||||
}
|
||||
@@ -117,15 +119,15 @@ const project = {
|
||||
|
||||
const measurement = {
|
||||
get_measurement_image: async function (projectId, orderId) {
|
||||
const projectPath = `${projectId}`;
|
||||
const imagePath = `${projectPath}/images/${orderId}.jpg`;
|
||||
const projectPath = path.join(PROJECTS_DIR, 'storage', `${projectId}`);
|
||||
const imagePath = path.join(projectPath, 'images', `${orderId}.jpg`);
|
||||
console.log("[FILE] get_measurement_image : " + imagePath);
|
||||
return await handleFileOperation(getFile, imagePath);
|
||||
},
|
||||
|
||||
upload_measurement_image: async function (image, projectId, orderId) {
|
||||
const projectPath = `${projectId}`;
|
||||
const imagePath = `${projectPath}/images/${orderId}.jpg`;
|
||||
const projectPath = path.join(PROJECTS_DIR, 'storage', `${projectId}`);
|
||||
const imagePath = path.join(projectPath, 'images', `${orderId}.jpg`);
|
||||
console.log("[FILE] upload_measurement_image : " + imagePath);
|
||||
await handleFileOperation(saveFile, imagePath, image.buffer);
|
||||
return imagePath;
|
||||
@@ -158,8 +160,8 @@ const measurement = {
|
||||
|
||||
const video = {
|
||||
get_video: async function (projectId, orderId) {
|
||||
const projectPath = `${projectId}`;
|
||||
const videoPath = `${projectPath}/videos/${orderId}.mp4`;
|
||||
const projectPath = path.join(PROJECTS_DIR, `${projectId}`);
|
||||
const videoPath = `/storage/${projectPath}/videos/${orderId}.mp4`;
|
||||
console.log("[FILE] get_video : " + videoPath);
|
||||
return await handleFileOperation(getFile, videoPath);
|
||||
},
|
||||
|
||||
@@ -259,8 +259,8 @@ const video = {
|
||||
|
||||
const camera = {
|
||||
get_camera: handleDatabaseOperation(async () => {
|
||||
const query = `SELECT * FROM camera;`;
|
||||
return (await db.query(query)).rows;
|
||||
const query = `SELECT * FROM camera WHERE id = 1;`;
|
||||
return (await db.query(query)).rows[0];
|
||||
}),
|
||||
|
||||
edit_camera: handleDatabaseOperation(async (id, updates) => {
|
||||
@@ -276,6 +276,12 @@ const camera = {
|
||||
})
|
||||
};
|
||||
|
||||
// zone de test
|
||||
async function test_zone(){
|
||||
}
|
||||
|
||||
test_zone();
|
||||
|
||||
// Export des modules
|
||||
module.exports = {
|
||||
project,
|
||||
|
||||
Reference in New Issue
Block a user