This commit is contained in:
andrei-mihnea-cerbu
2024-04-23 20:59:23 +03:00
parent 677295e176
commit 754ca11887
20 changed files with 106 additions and 20 deletions
+28
View File
@@ -0,0 +1,28 @@
const fs = require('fs');
const path = require('path');
// List of files you want to check and delete
const filesToDelete = [
path.join(__dirname, '..', 'backupSchemes.json'),
path.join(__dirname, '..', 'dirBackup.json'),
path.join(__dirname, '..', 'dirShare.json'),
path.join(__dirname, '..', 'usersInSystem.json'),
path.join(__dirname, '..', 'loginData.json'),
path.join(__dirname, '..', 'ipConfig.json')
];
filesToDelete.forEach(file => {
fs.access(file, fs.constants.F_OK, (err) => {
if (!err) {
fs.unlink(file, err => {
if (err) {
console.error(`Failed to delete ${file}: ${err}`);
} else {
console.log(`${file} was deleted successfully.`);
}
});
} else {
console.log(`${file} does not exist.`);
}
});
});
+3 -3
View File
@@ -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);
}
@@ -160,10 +160,10 @@ app.post('/upload', (req, res) => {
await fsExtra.move(req.file.path, finalPath, { overwrite: true });
await addFilePathToJson(finalPath);
res.status(httpStatus.OK).json({message: 'Upload successful.'})
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.'});
res.status(httpStatus.INTERNAL_SERVER_ERROR).json({ message: 'Server error while moving the file.' });
}
});
});