v2.3
This commit is contained in:
Generated
+1
-1
@@ -1 +1 @@
|
||||
external_endpoints.js
|
||||
sending_file_confirmation.js
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -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.' });
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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"
|
||||
},
|
||||
|
||||
@@ -72,6 +72,13 @@ const checkForServerConnection = async () => {
|
||||
} catch (error) {
|
||||
console.error("Error:", error);
|
||||
return false;
|
||||
} finally{
|
||||
try{
|
||||
fs.unlinkSync(pathToIpConfig);
|
||||
}
|
||||
catch{
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -6,13 +6,26 @@ document.addEventListener("DOMContentLoaded", async function () {
|
||||
|
||||
const uploadPromises = uploadData.users.map(async (user) => {
|
||||
try {
|
||||
const response = await fetch(uploadData.filePath);
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to fetch file');
|
||||
}
|
||||
const file = await response.blob();
|
||||
if (!file.size) {
|
||||
throw new Error('File is empty or could not be loaded');
|
||||
}
|
||||
|
||||
const formData = new FormData();
|
||||
const file = await fetch(uploadData.filePath).then(response => response.blob());
|
||||
formData.append('file', file);
|
||||
formData.append('idUser', user.userId);
|
||||
formData.append('nameOfFile', user.fileName);
|
||||
formData.append('sizeOfFile', file.size);
|
||||
|
||||
// Debugging FormData content
|
||||
for (let [key, value] of formData.entries()) {
|
||||
console.log(key, value instanceof Blob ? `Blob (${value.size} bytes)` : value);
|
||||
}
|
||||
|
||||
await timeout(5000); // Timeout to simulate delay or wait
|
||||
const url = `http://${user.destIp}:${user.destPort}/upload`;
|
||||
const uploadResponse = await fetch(url, {
|
||||
method: 'POST',
|
||||
@@ -20,7 +33,13 @@ document.addEventListener("DOMContentLoaded", async function () {
|
||||
});
|
||||
|
||||
if (!uploadResponse.ok) {
|
||||
throw new Error(`HTTP error during file upload to ${user.userId}: status ${uploadResponse.status}`);
|
||||
try {
|
||||
const errorResponse = await uploadResponse.json();
|
||||
throw new Error(`HTTP error during file upload to ${user.userId}: ${errorResponse.message}`);
|
||||
} catch (parseError) {
|
||||
const responseText = await uploadResponse.text();
|
||||
throw new Error(`HTTP error during file upload to ${user.userId}: ${responseText}`);
|
||||
}
|
||||
}
|
||||
|
||||
return {userId: user.userId, success: true, message: `Upload successful for user ${user.userId}`};
|
||||
@@ -32,9 +51,7 @@ document.addEventListener("DOMContentLoaded", async function () {
|
||||
|
||||
const results = await Promise.all(uploadPromises);
|
||||
results.forEach(result => {
|
||||
if (result.success) {
|
||||
console.log(result.message);
|
||||
}
|
||||
});
|
||||
console.log('All files processed. Check the console for detailed results.');
|
||||
} catch (error) {
|
||||
@@ -49,6 +66,6 @@ document.addEventListener("DOMContentLoaded", async function () {
|
||||
}
|
||||
|
||||
await performUploads();
|
||||
await timeout(10000);
|
||||
await timeout(10000); // Consider the necessity of this delay in production
|
||||
fadeOut('main_menu.html');
|
||||
});
|
||||
Generated
+1
-1
@@ -1 +1 @@
|
||||
login.css
|
||||
sending_file_confirmation.js
|
||||
@@ -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.`);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -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"
|
||||
},
|
||||
|
||||
@@ -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}`};
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user