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
+1 -1
View File
@@ -1 +1 @@
login.css
sending_file_confirmation.js
+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.`);
}
});
});
+1
View File
@@ -5,6 +5,7 @@
"description": "Aplicatie P2P pentru stocarea resurselor digitale",
"main": "src/main/main.js",
"scripts": {
"clean": "node ./jobs/clean.js",
"start": "electron --trace-warnings ./src/main/main.js",
"dev": "electronmon --trace-warnings ./src/main/main.js"
},
+4 -3
View File
@@ -19,9 +19,10 @@ document.addEventListener('DOMContentLoaded', async function () {
await window.electronAPI.writeFile('ipConfig.json', JSON.stringify({ip: ipAddress}));
fadeOut('login.html');
})
.catch(error => {
console.error('Error:', error.message);
throw new Error(error.message);
.catch(async error => {
await window.electronAPI.showAlert('Can\'t reach server.')
.then(() => console.log('Alert window opened'))
.catch(error => console.error('Error showing alert:', error));
});
} catch (error) {
console.error('Error:', error.message);
@@ -11,6 +11,7 @@ document.addEventListener("DOMContentLoaded", async function () {
formData.append('file', file);
formData.append('idUser', user.userId);
formData.append('nameOfFile', user.fileName);
formData.append('sizeOfFile', file.size);
await timeout(5000); // Timeout to simulate delay or wait
const url = `http://${user.destIp}:${user.destPort}/upload`;
@@ -20,7 +21,8 @@ document.addEventListener("DOMContentLoaded", async function () {
});
if (!uploadResponse.ok) {
throw new Error(`HTTP error during file upload to ${user.userId}: status ${uploadResponse.status}`);
const response = await uploadResponse.json()
throw new Error(`HTTP error during file upload to ${user.userId}: status ${response.message}`);
}
return {userId: user.userId, success: true, message: `Upload successful for user ${user.userId}`};