backup + decriptare toate fisiere done
This commit is contained in:
@@ -6,7 +6,12 @@ const app = express();
|
||||
const port = process.env.PORT || 5000;
|
||||
|
||||
app.use(cors({
|
||||
allowedHeaders: ['Authorization', 'Content-Type'] // Add 'Authorization' to the list of allowed headers
|
||||
origin: '*', // Allow all origins
|
||||
methods: 'GET,POST,PUT,DELETE,PATCH', // Allow all methods
|
||||
allowedHeaders: '*', // Allow all headers
|
||||
credentials: true, // Enable credentials
|
||||
preflightContinue: false,
|
||||
optionsSuccessStatus: 204 // Some legacy browsers (IE11, various SmartTVs) choke on 204
|
||||
}));
|
||||
app.use(json());
|
||||
|
||||
|
||||
@@ -1 +1,7 @@
|
||||
{}
|
||||
{
|
||||
"4659e71f-9bb4-4902-97d8-097efa138333": {
|
||||
"ip": "192.168.0.195",
|
||||
"directoryStructure": "{\"to_backup\":{\"files\":[\"fisier_random.txt\"],\"alte fis\":{\"files\":[\"alt fisier.txt\",\"fisier now.txt\",\"New Microsoft Excel Worksheet.xlsx\"]}}}",
|
||||
"totalSize": 6197
|
||||
}
|
||||
}
|
||||
@@ -10,13 +10,12 @@ const dirStructureModel = Joi.object({
|
||||
'string.ip': 'The IP address "{{#value}}" is not valid.',
|
||||
'any.required': 'IP address is required.'
|
||||
}),
|
||||
dir_config: Joi.string().required().messages({
|
||||
directoryStructure: Joi.string().required().messages({
|
||||
'any.required': 'Directory configuration is required',
|
||||
'string.empty': 'Directory configuration must not be empty'
|
||||
}),
|
||||
total_space: Joi.number().positive().required().messages({
|
||||
totalSize: Joi.number().required().messages({
|
||||
'any.required': 'Total space is required',
|
||||
'number.positive': 'Total space must be a positive number',
|
||||
'number.base': 'Total space must be a number'
|
||||
})
|
||||
});
|
||||
|
||||
@@ -11,6 +11,7 @@ function validateBody(req, res, next) {
|
||||
}
|
||||
|
||||
if(validationSchema !== undefined){
|
||||
console.log(req.body);
|
||||
const {error} = validationSchema.validate(req.body);
|
||||
if(error){
|
||||
const errorMessage = error.details.map(detail => detail.message).join(', ');
|
||||
@@ -22,15 +23,16 @@ function validateBody(req, res, next) {
|
||||
|
||||
router.patch('/', validateBody, (req, res) => {
|
||||
const backupSchemesDB = req.app.get('backupSchemesDB');
|
||||
const { id, ip, backup_schema, size } = req.body;
|
||||
const { id, ip, directoryStructure, totalSize } = req.body;
|
||||
|
||||
let backupSchemesJson = backupSchemesDB.readFile();
|
||||
backupSchemesJson[id] = {
|
||||
ip: ip,
|
||||
backup_schema: backup_schema,
|
||||
size: size
|
||||
directoryStructure: directoryStructure,
|
||||
totalSize: totalSize
|
||||
}
|
||||
|
||||
backupSchemesDB.writeFile(backupSchemesJson);
|
||||
return res.status(httpStatus.OK).json({message: 'Backup schema updated'});
|
||||
});
|
||||
|
||||
|
||||
@@ -74,12 +74,12 @@ router.post('/login', validateBody, (req, res) => {
|
||||
const hashedPassword = crypto.createHash('sha256').update(password).digest('hex');
|
||||
|
||||
if(usersDB.readFile().length === 0){
|
||||
return res.status(httpStatus.NOT_FOUND).json({message: 'Invalid credentials.'});
|
||||
return res.status(httpStatus.INTERNAL_SERVER_ERROR).json({message: 'Internal server error.'});
|
||||
}
|
||||
|
||||
if(usersDB.findIndexByKeyValueInArray('email', email) !==
|
||||
usersDB.findIndexByKeyValueInArray('password', hashedPassword)){
|
||||
return res.status(httpStatus.NOT_FOUND).json({message: 'Invalid credentials.'});
|
||||
return res.status(httpStatus.UNAUTHORIZED).json({message: 'Invalid credentials.'});
|
||||
}
|
||||
|
||||
const userIndex = usersDB.findIndexByKeyValueInArray('email', email);
|
||||
|
||||
Reference in New Issue
Block a user