This commit is contained in:
andrei-mihnea-cerbu
2024-04-22 16:30:40 +03:00
parent 7cf1729d08
commit 9ac718bea3
24 changed files with 275 additions and 163 deletions
+4
View File
@@ -52,6 +52,10 @@ app.use('/admin', adminRouter);
app.use('/ceo', ceoRouter);
app.use('/backup_schemes', backupSchemesRouter);
app.use('/heartbeat', (req, res) => {
return res.status(200).json({message: 'Server ap and running.'});
})
app.listen(port, () => {
console.log(`Server running on http://localhost:${port}`);
});
+12 -1
View File
@@ -1 +1,12 @@
{}
{
"7c0ef9d5-23ed-47a6-bfb4-fdcfce436904": {
"ip": "192.168.0.195",
"directoryStructure": "{\"backup_dir\":{\"files\":[],\"fisiere\":{\"files\":[\"New Microsoft Excel Worksheet.xlsx\",\"New Microsoft Word Document.docx\"]}}}",
"totalSize": 19363
},
"59c712d9-e6dd-438f-aec9-31ca2ae750e6": {
"ip": "192.168.0.195",
"directoryStructure": "{\"backup_dir\":{\"files\":[],\"fisiere\":{\"files\":[\"New Microsoft Excel Worksheet.xlsx\",\"New Microsoft Word Document.docx\"]}}}",
"totalSize": 19363
}
}
+20 -1
View File
@@ -1,4 +1,23 @@
const express = require('express');
const checkForServerConnection = async () => {
const pathToIpConfig = path.join(__dirname, '..', '..', 'ipConfig.json');
await lockFile.lock(pathToIpConfig);
try {
await decryptFileInPlace(pathToIpConfig);
const ipConfig = await fs.readFile(pathToIpConfig, 'utf-8');
const { ip } = JSON.parse(ipConfig);
const response = await fetch(`http://${ip}:5000/heartbeat`);
if (response.ok) {
return true;
} else {
return false;
}
} catch (error) {
console.error("Error:", error);
return false;
} finally {
await lockFile.unlock(pathToIpConfig);
}
};const express = require('express');
const crypto = require('crypto');
const { v4: uuidv4 } = require('uuid');