diff --git a/CEO/jobs/external_endpoints.js b/CEO/jobs/external_endpoints.js index c8add05..5a8fe16 100644 --- a/CEO/jobs/external_endpoints.js +++ b/CEO/jobs/external_endpoints.js @@ -99,7 +99,7 @@ async function addFilePathToJson(filePath) { if (await fsExtra.pathExists(jsonFilePath)) { await lockFile(jsonFilePath); data = await fsExtra.readJson(jsonFilePath); - } else { + }else{ await lockFile(jsonFilePath); } @@ -114,21 +114,9 @@ async function addFilePathToJson(filePath) { } } -const shareFileSchema = Joi.object({ - idUser: Joi.string().required(), - nameOfFile: Joi.string().required(), - sizeOfFile: Joi.number().required() -}); - const storage = multer.diskStorage({ destination: function (req, file, cb) { - const { error, value } = shareFileSchema.validate(req.body); - if (error) { - cb(error, undefined); - return; - } - - const baseDir = path.join(__dirname, '..', 'uploads', value.idUser); // Temp storage location + const baseDir = path.join(__dirname, '..', 'uploads', req.body.idUser); // Temp storage location fsExtra.ensureDirSync(baseDir); cb(null, baseDir); }, @@ -139,38 +127,39 @@ const storage = multer.diskStorage({ const upload = multer({ storage: storage }).single('file'); -app.post('/upload', (req, res) => { - upload(req, res, async (err) => { - if (err instanceof multer.MulterError) { - res.status(httpStatus.INTERNAL_SERVER_ERROR).send(`Multer error: ${err.message}`); - return; - } else if (err) { - res.status(httpStatus.BAD_REQUEST).send(`Validation error: ${err.message}`); - return; - } - - try { - const { idUser, nameOfFile } = req.body; - - const dirConfig = await fsExtra.readJson(path.join(__dirname, '..', 'dirShare.json')); - const baseDir = dirConfig.path; - - const finalPath = path.join(baseDir, idUser, nameOfFile); - - await fsExtra.move(req.file.path, finalPath, { overwrite: true }); - await addFilePathToJson(finalPath); - - res.status(httpStatus.OK).json({ message: 'Upload successful.' }); - } catch (error) { - console.error('Failed to move file:', error); - res.status(httpStatus.INTERNAL_SERVER_ERROR).json({ message: 'Server error while moving the file.' }); - } +// Route for file upload +app.post('/upload', async (req, res) => { + const shareFileSchema = Joi.object({ + idUser: Joi.string().required(), + nameOfFile: Joi.string().required(), + sizeOfFile: Joi.number().required() }); + + try { + const { error, value } = shareFileSchema.validate(req.body); + if (error) { + return res.status(httpStatus.BAD_REQUEST).send(`Validation error: ${error.message}`); + } + + await upload(req, res, async (err) => { + if (err instanceof multer.MulterError) { + res.status(httpStatus.INTERNAL_SERVER_ERROR).send(`Multer error: ${err.message}`); + return; + } else if (err) { + res.status(httpStatus.BAD_REQUEST).send(`Upload error: ${err.message}`); + return; + } + + // File upload logic + res.status(httpStatus.OK).json({ message: 'Upload successful.' }); + }); + } catch (error) { + console.error('Error during file upload:', error); + res.status(httpStatus.INTERNAL_SERVER_ERROR).json({ message: 'Internal server error.' }); + } }); - - console.log('external_endpoints.json started.'); const PORT = process.env.PORT || 3000; server.listen(PORT, () => console.log(`Server running on port ${PORT}`)); diff --git a/UC/Dockerfile b/UC/Dockerfile deleted file mode 100644 index 0221513..0000000 --- a/UC/Dockerfile +++ /dev/null @@ -1,23 +0,0 @@ -# Use the latest official Node runtime as a parent image -FROM node:latest - -# Set the working directory in the container -WORKDIR /usr/src/app - -# Copy package.json and package-lock.json (if available) -COPY package*.json ./ - -# Install any needed packages specified in package.json -RUN npm install - -# Bundle app source inside Docker image -COPY . . - -# Make ports 80, 3000, and 5000 available to the world outside this container -EXPOSE 80 3000 5000 - -# Define environment variable -ENV NODE_ENV=production - -# Run the app when the container launches -CMD ["npm", "start"] diff --git a/UC/backend/src/db/backup_schemes.json b/UC/backend/src/db/backup_schemes.json index 3fa40ef..97eca47 100644 --- a/UC/backend/src/db/backup_schemes.json +++ b/UC/backend/src/db/backup_schemes.json @@ -5,7 +5,7 @@ "totalSize": 19363 }, "59c712d9-e6dd-438f-aec9-31ca2ae750e6": { - "ip": "192.168.0.195", + "ip": "192.168.0.18", "directoryStructure": "{\"backup_dir\":{\"files\":[],\"fisiere\":{\"files\":[\"New Microsoft Excel Worksheet.xlsx\",\"New Microsoft Word Document.docx\"]}}}", "totalSize": 19363 } diff --git a/User/jobs/external_endpoints.js b/User/jobs/external_endpoints.js index 8b12e01..5a8fe16 100644 --- a/User/jobs/external_endpoints.js +++ b/User/jobs/external_endpoints.js @@ -114,21 +114,9 @@ async function addFilePathToJson(filePath) { } } -const shareFileSchema = Joi.object({ - idUser: Joi.string().required(), - nameOfFile: Joi.string().required(), - sizeOfFile: Joi.number().required() -}); - const storage = multer.diskStorage({ destination: function (req, file, cb) { - const { error, value } = shareFileSchema.validate(req.body); - if (error) { - cb(error, undefined); - return; - } - - const baseDir = path.join(__dirname, '..', 'uploads', value.idUser); // Temp storage location + const baseDir = path.join(__dirname, '..', 'uploads', req.body.idUser); // Temp storage location fsExtra.ensureDirSync(baseDir); cb(null, baseDir); }, @@ -139,38 +127,39 @@ const storage = multer.diskStorage({ const upload = multer({ storage: storage }).single('file'); -app.post('/upload', (req, res) => { - upload(req, res, async (err) => { - if (err instanceof multer.MulterError) { - res.status(httpStatus.INTERNAL_SERVER_ERROR).send(`Multer error: ${err.message}`); - return; - } else if (err) { - res.status(httpStatus.BAD_REQUEST).send(`Validation error: ${err.message}`); - return; - } - - try { - const { idUser, nameOfFile } = req.body; - - const dirConfig = await fsExtra.readJson(path.join(__dirname, '..', 'dirShare.json')); - const baseDir = dirConfig.path; - - const finalPath = path.join(baseDir, idUser, nameOfFile); - - await fsExtra.move(req.file.path, finalPath, { overwrite: true }); - await addFilePathToJson(finalPath); - - res.status(httpStatus.OK).json({message: 'Upload successful.'}) - } catch (error) { - console.error('Failed to move file:', error); - res.status(httpStatus.INTERNAL_SERVER_ERROR).json({message: 'Server error while moving the file.'}); - } +// Route for file upload +app.post('/upload', async (req, res) => { + const shareFileSchema = Joi.object({ + idUser: Joi.string().required(), + nameOfFile: Joi.string().required(), + sizeOfFile: Joi.number().required() }); + + try { + const { error, value } = shareFileSchema.validate(req.body); + if (error) { + return res.status(httpStatus.BAD_REQUEST).send(`Validation error: ${error.message}`); + } + + await upload(req, res, async (err) => { + if (err instanceof multer.MulterError) { + res.status(httpStatus.INTERNAL_SERVER_ERROR).send(`Multer error: ${err.message}`); + return; + } else if (err) { + res.status(httpStatus.BAD_REQUEST).send(`Upload error: ${err.message}`); + return; + } + + // File upload logic + res.status(httpStatus.OK).json({ message: 'Upload successful.' }); + }); + } catch (error) { + console.error('Error during file upload:', error); + res.status(httpStatus.INTERNAL_SERVER_ERROR).json({ message: 'Internal server error.' }); + } }); - - console.log('external_endpoints.json started.'); const PORT = process.env.PORT || 3000; server.listen(PORT, () => console.log(`Server running on port ${PORT}`));