v2.3
This commit is contained in:
@@ -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.`);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -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.' });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user