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) => {
|
const uploadPromises = uploadData.users.map(async (user) => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(uploadData.filePath);
|
const fileResponse = await fetch(uploadData.filePath);
|
||||||
if (!response.ok) {
|
if (!fileResponse.ok) {
|
||||||
throw new Error('Failed to fetch file');
|
throw new Error(`HTTP error when trying to fetch the file: status ${fileResponse.statusText}`);
|
||||||
}
|
|
||||||
const file = await response.blob();
|
|
||||||
if (!file.size) {
|
|
||||||
throw new Error('File is empty or could not be loaded');
|
|
||||||
}
|
}
|
||||||
|
const fileBlob = await fileResponse.blob();
|
||||||
|
|
||||||
const formData = new FormData();
|
await timeout(5000); // Timeout to simulate delay or wait
|
||||||
formData.append('file', file);
|
const url = `http://${user.destIp}:${user.destPort}/share_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);
|
|
||||||
}
|
|
||||||
|
|
||||||
const url = `http://${user.destIp}:${user.destPort}/upload`;
|
|
||||||
const uploadResponse = await fetch(url, {
|
const uploadResponse = await fetch(url, {
|
||||||
method: 'POST',
|
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) {
|
if (!uploadResponse.ok) {
|
||||||
try {
|
const response = await uploadResponse.json();
|
||||||
const errorResponse = await uploadResponse.json();
|
throw new Error(`HTTP error during file upload to ${user.userId}: status ${response.message}`);
|
||||||
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}`};
|
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);
|
const results = await Promise.all(uploadPromises);
|
||||||
results.forEach(result => {
|
results.forEach(result => {
|
||||||
|
if (result.success) {
|
||||||
console.log(result.message);
|
console.log(result.message);
|
||||||
|
} else {
|
||||||
|
console.error(result.message);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
console.log('All files processed. Check the console for detailed results.');
|
console.log('All files processed. Check the console for detailed results.');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -66,6 +59,7 @@ document.addEventListener("DOMContentLoaded", async function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await performUploads();
|
await performUploads();
|
||||||
await timeout(3000); // Consider the necessity of this delay in production
|
await timeout(3000);
|
||||||
fadeOut('main_menu.html');
|
fadeOut('main_menu.html'); // Make sure this function is properly defined or available in your context
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -1,11 +1,11 @@
|
|||||||
{
|
{
|
||||||
"7c0ef9d5-23ed-47a6-bfb4-fdcfce436904": {
|
"7c0ef9d5-23ed-47a6-bfb4-fdcfce436904": {
|
||||||
"ip": "192.168.0.195",
|
"ip": "192.168.169.19",
|
||||||
"directoryStructure": "{\"backup_dir\":{\"files\":[],\"fisiere\":{\"files\":[\"New Microsoft Excel Worksheet.xlsx\",\"New Microsoft Word Document.docx\"]}}}",
|
"directoryStructure": "{\"backup_dir\":{\"files\":[],\"fisiere\":{\"files\":[\"New Microsoft Excel Worksheet.xlsx\",\"New Microsoft Word Document.docx\"]}}}",
|
||||||
"totalSize": 19363
|
"totalSize": 19363
|
||||||
},
|
},
|
||||||
"59c712d9-e6dd-438f-aec9-31ca2ae750e6": {
|
"59c712d9-e6dd-438f-aec9-31ca2ae750e6": {
|
||||||
"ip": "192.168.0.18",
|
"ip": "192.168.169.53",
|
||||||
"directoryStructure": "{\"backup_dir\":{\"files\":[],\"fisiere\":{\"files\":[\"New Microsoft Excel Worksheet.xlsx\",\"New Microsoft Word Document.docx\"]}}}",
|
"directoryStructure": "{\"backup_dir\":{\"files\":[],\"fisiere\":{\"files\":[\"New Microsoft Excel Worksheet.xlsx\",\"New Microsoft Word Document.docx\"]}}}",
|
||||||
"totalSize": 19363
|
"totalSize": 19363
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user