v3.0
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"7c0ef9d5-23ed-47a6-bfb4-fdcfce436904": {
|
||||
"ip": "192.168.169.19",
|
||||
"directoryStructure": "{\"backup_dir\":{\"files\":[],\"fisiere\":{\"files\":[\"New Microsoft Excel Worksheet.xlsx\",\"New Microsoft Word Document.docx\"]}}}",
|
||||
"totalSize": 19363
|
||||
},
|
||||
"59c712d9-e6dd-438f-aec9-31ca2ae750e6": {
|
||||
"ip": "192.168.169.53",
|
||||
"directoryStructure": "{\"backup_dir\":{\"files\":[],\"fisiere\":{\"files\":[\"New Microsoft Excel Worksheet.xlsx\",\"New Microsoft Word Document.docx\"]}}}",
|
||||
"totalSize": 19363
|
||||
}
|
||||
}
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"path": "/home/andrei/Desktop/proiect-licenta/dirs/ceo/backup_dir",
|
||||
"structure": {
|
||||
"backup_dir": {
|
||||
"files": [],
|
||||
"fisiere": {
|
||||
"files": [
|
||||
"New Microsoft Excel Worksheet.xlsx",
|
||||
"New Microsoft Word Document.docx"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"size": 19363
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"path": "/home/andrei/Desktop/proiect-licenta/dirs/ceo/share_dir"
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
b=КxЉјврgi”ГT§мcQБ,|‚В{u«к
|
||||
Binary file not shown.
@@ -6,40 +6,29 @@ 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 fileResponse = await fetch(uploadData.filePath);
|
||||
if (!fileResponse.ok) {
|
||||
throw new Error(`HTTP error when trying to fetch the file: status ${fileResponse.statusText}`);
|
||||
}
|
||||
const fileBlob = await fileResponse.blob();
|
||||
|
||||
const formData = new FormData();
|
||||
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}/share_file`;
|
||||
|
||||
// Debugging FormData content
|
||||
for (let [key, value] of formData.entries()) {
|
||||
console.log(key, value instanceof Blob ? `Blob (${value.size} bytes)` : value);
|
||||
}
|
||||
|
||||
const url = `http://${user.destIp}:${user.destPort}/upload`;
|
||||
const uploadResponse = await fetch(url, {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
headers: {
|
||||
'Content-Type': 'application/octet-stream',
|
||||
'X-IdUser': user.userId,
|
||||
'X-NameOfFile': user.fileName,
|
||||
'X-SizeOfFile': fileBlob.size
|
||||
},
|
||||
body: fileBlob
|
||||
});
|
||||
|
||||
if (!uploadResponse.ok) {
|
||||
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}`);
|
||||
}
|
||||
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}`};
|
||||
@@ -51,7 +40,11 @@ document.addEventListener("DOMContentLoaded", async function () {
|
||||
|
||||
const results = await Promise.all(uploadPromises);
|
||||
results.forEach(result => {
|
||||
console.log(result.message);
|
||||
if (result.success) {
|
||||
console.log(result.message);
|
||||
} else {
|
||||
console.error(result.message);
|
||||
}
|
||||
});
|
||||
console.log('All files processed. Check the console for detailed results.');
|
||||
} catch (error) {
|
||||
@@ -66,6 +59,7 @@ document.addEventListener("DOMContentLoaded", async function () {
|
||||
}
|
||||
|
||||
await performUploads();
|
||||
await timeout(3000); // Consider the necessity of this delay in production
|
||||
fadeOut('main_menu.html');
|
||||
await timeout(3000);
|
||||
fadeOut('main_menu.html'); // Make sure this function is properly defined or available in your context
|
||||
});
|
||||
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user